Posts

Showing posts with the label rendering

reactJS rendering empty data

Image
Clash Royale CLAN TAG #URR8PPP reactJS rendering empty data When I am fetching the data I want them to fetch first and then render. It always renders empty string even when I'm setting the state and I don't understand why. class App extends React.Component { constructor () { super() this.state = { view: 'feed', posts: '' //data I want to render } this.changeView = this.changeView.bind(this) } componentDidMount () { this.getAllPosts() //getting the data } getAllPosts () { axios.get('/api/blogs') .then((response) => { console.log(response) this.setState({ posts: response }) }) .catch((error) => { console.log(error) }) } changeView(option) { this.setState({ view: option }) } renderView () { const {view} = this.state if (view === 'feed') { return <Feed blogs={this.state.posts} handleClick={() =...