How to use fetched data as State?
I am getting data (a post) from trpc inside my component:
The user should be able to edit the post, so I want to make the fetched data a state via useState.
I tried:
but it doesnt work.
I need to set the State after the data finished loading. How?
12 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I thought in order for a user to modify the post (and then eventually re-write that modification to the database), it would make sense to manage a state. This way, the user can modify whatever attribute of the state that he wants, and in the end, I just take that state and write to db
I don't think postData can be regarded as a state. I can't do something like setPostData(), right?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ye that makes sense
React Query and Forms
Forms tend to blur the line between server and client state, so let's see how that plays together with React Query.
but when they are edited, where to save the changes to?
I can only think of useState
this article gives you a couple of different options
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ye just imagine that the only thing that changes when you edit the post is that the input field it's in, becomes editable
so I guess preview, yeah
using the simple approach (https://tkdodo.eu/blog/react-query-and-forms#the-simple-approach), do I have to use the useMutation hook? because right now I get an error
Argument of type 'void' is not assignable to parameter of type 'SubmitHandler<FieldValues>'.ts(2345)
while doing this:React Query and Forms
Forms tend to blur the line between server and client state, so let's see how that plays together with React Query.
nevermind, me stupid