-3

I'm stuck in updating states , I'm using a function for generalising a Modal from a 3rd party framework now when I want to update the particular variable I'm stuck as dynamically its not updating ,i.e: Ex: setModalState(...oldstate,v1:{v2:false}} . Here ${v1} and ${v2} are already in old state and I passed to function as props but javascript is not taking insted taking v1,v2; I have attached few photos for understanding

https://res.cloudinary.com/df2q7cryi/image/upload/v1615998821/error3_svxlcw.png

https://res.cloudinary.com/df2q7cryi/image/upload/v1615998764/eroor2_enjcbc.png

https://res.cloudinary.com/df2q7cryi/image/upload/v1615998762/eroor_bz5wwf.png

1 Answer 1

0

Solution is to use | setModalState({...modalstate,[section]:{[purpose]:false}})}

Reference : https://stackoverflow.com/questions/9398535/add-dynamic-key-value-pairs-to-javascript-array-or-hash-table/9398583#:~:text=You%20need%20to%20define%20an,square%20bracket%20and%20dot%20notation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.