I have shown data using ReactJS but now I want to use Redux to show data instead. I tried but it’s too much error,so I will not put my redux code up. So how can I do?
Here’s my code using ReactJS only
Example.js
export default class Example extends Component {
constructor(props) {
super(props);
this.state = {posts: []};
}
componentWillMount(){
axios.get('http://127.0.0.1:8000/posts')
.then(response => {
this.setState({ posts: response.data });
})
}
postRow(p){
return (
<tr key = {p.id}>
<td>{p.title}</td>
<td>{p.description}</td>
</tr>
)
}
render() {
const posts = this.state.posts.map(post => this.postRow(post));
return (<div>
<table border="1">
<thead>
<tr><th>Title</th><th>Description</th></tr>
</thead>
<tbody>{ posts }</tbody>
</table>
</div>
);
}
}
RoutePath.js
export default class RoutePath extends Component{
render(){
return(
<BrowserRouter>
<Switch><Route exact path='/' component={Example}/></Switch>
</BrowserRouter>
)
}
}
ReactDOM.render(<RoutePath/>,document.getElementById('homepage'));