Code-Along: Edit Dino Blog
Last updated
Last updated
Deliverable:
Let's implement state in our blog by making the body
or content
a mutable value.
Set an initial state prop in your component that contains content or body for posts.
Add a button to somewhere in your page (up to you which component to add to!). This button should onClick
open an alert that takes a value.
Take the user inputed value into the alert box and use that return value to update the state of the body or content of your post.
Some things to note:
Set an initial state for our App
component. The state
object should have an attribute called body
. Remove the prop we set for App
and put it into the initial state instead. The value of this.state.body
should be Check out this body property!
.
Modify App
's render()
method so that it uses the body
from state, not props.
Create a changeBody()
method inside App
that updates body
based on a user's input.
You should use setState
somewhere in this method.
How can you get user input? Keep it simple and start with prompt
.
Add a button to App
's render()
method that triggers changeBody()
.
This is what your solution should look like.