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

今天就学习课程吧!

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

Fetching data conditionally

Fetching data conditionally

- Let me review everything we did real quick. We changed the server to accept the path for a contest. We made server Render aware of it which means, when we go to a slash contest endpoint the initial data is going to have a current contest object and it will not have the contest list. It will only have a current contest object. We changed the app component to not rely on a current contest ID string, but rather on a current contest object. If there is a current contest object in the initial data, we render the contest page, otherwise we render the contest list page. If there is a current contest in the initial data then the current contest state element, here in the app component, will have that initial data. And to make all this work, when we set the current contest and we do that either when we navigate to a contest here or when we handle the state record going back to a contest page. We just fake an object that has the ID…

内容