I have a simple app that has 3 name change fields which I am trying to patch the API / DB with Axios.
I have three inputs and I want to change the same, if you look in the console log you will see the changes in the object.
My issue is with getting the data to send to the API / DB. I useState to 'hold' the new object in state and then pass that to the axios.patch method but it isn't working and I am not sure what I am doing wrong here.
Could someone cast an eye over it and point me in the right direction, please? Thank you! Dave :)
https://mi4436.csb.app/ <= web view
https://codesandbox.io/s/mi4436 <= code view
CodePudding user response:
You are trying to rewrite json file stored on clients browser using axios...
- React(without using some SSR framework or server components) is nearly everytime running on client. That means inside browser.
- Axios makes HTTP calls, it can't read/write to files in fileSystem
- What i know, there is no "legal" possibility to change files on clients side, except cookies.
Solution: If you want to make this work, you need to create server(nodejs, expressjs, java, php), which listen on some url, and this server will store your data in filesystem or database, and then you can make calls to this server using axios