function Route()
{
const [Items, setItems] = useState([]);
const [status, setQuotestatus] = useState(true);
const [quotation, setQuotation] = useState({quoteNo: "", type: "Project", quoteDate: "", validity: "", total: 0});
const callback = useCallback((Items,quotation) =>
{
setItems(Items);
setQuotation(quotation);
console.log(status)
setQuotestatus(!status);
console.log(quotation,status);
}, [],);
if(status)
{
return (<Quote allItems={Items} quote={quotation} parentCallback={callback} />);
}
else
{
return (<Documents Items={Items} quote={quotation} parentCallback={callback} />);
}
}
export default Route;
I'm using useCallBack to switch and pass parameters between 2 child components that have same parent component <Route />
. The default case and first switching is working on using use Callback, but when I tried to call this same useCallback from the next components it is calling the hook but component is not shifting to next.
That is I'm able to go to <Quote />
, then able move to <Documents />
. But unable to move back to <Quote />
from <Documents />
Button on <Quote />
<button type="button" className="btn btn-primary" onClick={(e) => {e.preventDefault(); parentCallback(storedItems, {quoteNo: quoteNo, type: type, quoteDate: quoteDate, validity: validity, total: total})}} >
Preview
</button>
Button on <Documents />
<div className="col">
<button type="button" className="btn btn-primary" onClick={(e) => {e.preventDefault(); parentCallback(storedItems, {quoteNo: quote.quoteNo, type: quote.type, quoteDate: quote.quoteDate, validity: quote.validity, total: quote.total})}} >Back</button>
</div>