Javascript 如何将状态从函数传递到类-reactjs
我正在使用Javascript 如何将状态从函数传递到类-reactjs,javascript,reactjs,react-hooks,Javascript,Reactjs,React Hooks,我正在使用挂钩。 我有一个函数可以使用dropzone库: export function UploadFile() { const [files] = useState([]); return ( <MaterialDropZone files={files} showPreviews maxSize={5000000} filesL
挂钩
。
我有一个函数可以使用dropzone
库:
export function UploadFile() {
const [files] = useState([]);
return (
<MaterialDropZone
files={files}
showPreviews
maxSize={5000000}
filesLimit={5}
text="to upload"
/>
);
}
class MyClass extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
...
render(){
return (
<UploadFile />)
}
export函数上传文件(){
const[files]=useState([]);
返回(
);
}
类MyClass扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
};
}
...
render(){
返回(
)
}
现在我想访问
组件中的文件
来上传我的文件。但是我不知道如何访问文件
您不能直接访问父组件中的子组件中定义的状态。
您可以在父组件MyClass
中定义files
状态,并将其作为道具传递给子组件UploadFile