Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to update state object with an array of strings as a value?

I have this following code the idea is I want to later concat those 2 stings together , which led to this logic, any idea how to handle updating this state ? the state is updated using a handchange function. but it is giving me an error A spread argument must either have a tuple type or be passed to a rest parameter. maybe my whole approach to updating the state in wrong.

    const [link, SetLink] = useState<{ site: string[] }>({ site: ['https://www.somesite.com/', ''] });
    
    SetLink(...link.site[1], (link.site[1] = target.value));

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

setLink(prevState => ({ site: [prevState.site[0], target.value] }))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading