I am trying to build a simple rails backend and react frontend blog app. Everything was going fine until I get to edit action when I was trying to edit a post. I can not set propTypes and using refs in form. I am getting the following error
[![see the below image link to see the error details][1]][1]
[1]: https://i.stack.imgur.com/VvdS0.png
I am using react-rails gem
here is my controller edit and update actions
def edit
@post = Post.find(params[:id])
end
def update
if @post.update(post_params)
render json: { post: @post }
else
render :edit
end
Thanks Implaier. That’s a good resource and those links are shown with the error but, unfortunately they didn’t help solving my issue. May be that’s because I am just a beginner with react. I want to build a full crud react-rails app. If anyone has any tutorial suggestions, that would be helpful. Thanks again Implaier. Your effort to help me is appreciated. May God bless you
Is there any particular reason that you need to use refs in your code, since they are used only in special cases? Otherwise it is much easier to implement a form with as a controlled component.
I am getting data from database. I don’t really know the right way to handle the update action.
I need to get the existing post title and body and update them. It’s my first time using react and implementing a crud app. my both get all posts and get a single post actions working just fine but I am stuck here in updating an existing post and I am sure that might happen when I get to (new/create) action.
I changed my form like this. I don’t know what am missing when I handleChange state, I get an error saying that “cannot read property title of undefined”
Thank you Implaier, That helped me handling setState and getting data but, I still have a rails-related issue. that definitely worked to get the data and handling setState. Thank you again, your help is appreciated!