L. Catalina Meneses
Software Developer at Ubidots Internet of Things. Co-organizer of @pionerasdev / Making history with {code} 👩💻
@kath-code
ReactJS
Setup React Routing.
Create List and Create pages.
Create each route for List and Create.
Create the state in APP to save the shareBook list.
Create the card components.
Render the shareBook list in the List component
Let's code!
$ npx create-react-app shared-book
...
Happy hacking!
...
$ cd shared-book
$ yarn start
Create the app shared-book
|-- src
| |-- pages
| | |--List
| | |--Create
| |-- containers
| | |--App
| |-- shared
| | |-- Header
| | |-- Container
| | |-- FloatingIcon
| | |-- Card
| | | |-- CardContent
| | | |-- CardFooter
ReactJS recomendations: https://reactjs.org/docs/faq-structure.html
Step 1: Create the shared components
Step 2: Setup React Router
$ yarn add react-router-dom
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
rebder (
<Router>
<div className="App">
<Switch>
<Route exact path="/">
<!-- Component to render -->
</Route>
</Switch>
</div>
</Router>
)
Npm: https://www.npmjs.com/package/react-router-dom
Yarn: https://yarnpkg.com/package/react-router-dom
Step 3: Create the pages: List and Create
Step 4: Create each router for: List and Create
<Router>
<div className="App">
<Switch>
<Route exact path="/">
<List />
</Route>
<Route path="/create">
<Create />
</Route>
</Switch>
</div>
</Router>
Step 5: Create the state in APP to save the shareBook list.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
shareBooks: [],
};
}
addShareBook = (newShareBook) => {
this.setState({
shareBooks: [...this.state.shareBooks, newShareBook],
});
};
render() {
...
}
}
Step 6: Create the card components
Step 7: Render the shareBook list in the List page.
Now is your time to improve this application
@kath-code
ReactJS
Thank you!
By L. Catalina Meneses
Software Developer at Ubidots Internet of Things. Co-organizer of @pionerasdev / Making history with {code} 👩💻