I'm using hooks
. I have a function to use dropzone
library:
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 />)
}
now I want to access files
inside MyClass
component to uplaod my files. but I don't know how to access files
.
you cannot access the state defined in child component in your parent component directly. What you can do is that you can define files
state in your parent component MyClass
and pass it as props in your child component UploadFile
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.