I have component TopPage
and ImagePreview
and FileUploader
-
At first
FileUploader
is shown, -
FileUploader changed the fileObj state of TopPage.
-
then,FileUploader disappeared and ImagePreview appreas, and at the same time useEffect() is called, but at this time, there is no
ImagePreviewRef
.
When useState is called , both component re-render and useEffect are called.
The order is useEffect -> re-render?
If so, how can I solve this problem?
const TopPage = (props) =>{
const [fileObj, setFileObj ] = useState();
useEffect(() =>{
imagePreviewRef.current.loadPic(fileObj);
},[fileObj]);
if (fileObj){
return <ImagePreview ref={imagePreviewRef}></ImagePreview>
}
else {
return <FileUploader SetFileObj=setFileObj></FileUploader>
}
}
const FileUploader = (props) => {
// props.setFileObj() is called here.
}
const ImagePreview = (props) => {
const loadPic = () =>{// loadpicture to canvas }
}