课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Updating UI based on API response

Updating UI based on API response

- [Instructor] So how do we update the list of proposed names without refreshing the page? Well, we're rendering the contest information from this contest object, which is a state element. So really, all we need to do is just set contest to be the updated contest and this would make the list of names refresh immediately 'cause React is going to take this updated contest and rerender this component based on updated contest and make its virtual diffing with the previously rendered output and it will figure out that it needs to go to the dom and update the list of names. And really only that because we have not updated anything else on the contest. And let me test that real quick. All right, let's do another awesome name. Inspect the network request. Make sure everything we see there is what to expect. Submit, the name showed up here. We have a 200 request to the API and it returned the updated contest information.

内容