import React from 'react'; // class组件 class ListClass extends React.Component { constructor(props) { super(props); } render() { const { list } = this.props; return ( { list.map(item => - item.id}>{ item.name}
)}
) } } // 函数组件 const ListFunc = (props) => { const { list } = props; return ( { list.map(item => - item.id}>{ item.name}
)}
) } export { ListClass, ListFunc }
import React from 'react'; // class组件 class Test extends React.Component { constructor(props) { super(props); this.fileInputRef = React.createRef(); this.nameInputRef = React.createRef(); } render() { return this.fileInputRef}/> } alertFile = () => { const elem = this.fileInputRef.current; alert(elem.value); // 不是this.fileInputRef.value } alertName = () => { const elem = this.nameInputRef.current; alert(elem.value); // 不是this.nameInputRef.value } } export default Test;
import React from 'react' import ReactDOM from 'react-dom' import './style.css' class App extends React.Component { constructor(props) { super(props) this