This is my code.
const initialNoticeState = {
id: props,
title : '',
description : '',
image : '',
updated_by : user.firstName+' '+user.lastName,
priority : ''
};
const [currentNotice, setCurrentNotice] = useState(initialNoticeState);
const notice = useSelector(state => state.notices.currentNotice)
const [noticeImage, setNoticeImage] = useState("");
const [imgData, setImgData] = useState(null);
const dispatch = useDispatch();
useEffect(() => {
dispatch(noticeActions.getById(props.id))
}, [props.id]);
I want to setCurrentNotice
from notice
value, just after dispatch
finishes.
Here is the data of notice
:
useEffect can be used to execute functions when variable is changed.