S
S
Sergey Zolotarev2022-04-18 11:23:15
React
Sergey Zolotarev, 2022-04-18 11:23:15

How to properly fetch data with conditional rendering?

Hello!

I am faced with the refinement of the site news list component in the admin panel , where in rendering I use a selection of the received data from the state, applying their conditional rendering:

{ this.state.newsList ? 
  this.state.newsList.map((myState) => {
    <div id="news">
      <header data-news={ mystate.id }>{ mystate.title }</header>
      <main>{ mystate.created }</main>
      <footer>Edit</footer>
    </div>
   }) : 'Not news matherials'
}

When the data is in the state, DevTools gave the same error twice:
ReferenceError: mystate is not defined

How to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HealSpirit, 2022-04-18
@HealSpirit

You have a myState variable in your function, but you use it as mystate
Ps div is still not drawn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question