Search code examples
reactjs

While using map() function props.data is undefined


  • It shows data without map function in console
  • But whenever I use map function it shows props.data is undefned and also undefined in console
  • I have used the same code for another page and that works
const Test_Footer = (props) => {
    console.log("ok", props.data)

    const newvar =props.data.map((item) => {
        return (
          <>
           <li>{item.data.id}</li> 
          </>  
        )
      })
    //   console.log(newvar)
    return (
        <div>
            <div class="main-content">
                <footer className="footer">
                    <div className="review-checkbox"><input type="checkbox" /><label>Review</label></div>
                    <div className="question-nav">
                        <ul className="pagination">
                            {newvar} 
                       </ul>
                        <button className="minimize-btn ml-10"><img src="images/minimize-btn.png" /></button>
                    </div>
                </footer>
            </div>
        </div >
    )
}
export default Test_Footer

Solution

  • const newvar = props && props.data && props.data.map((item) => {
            return (
                <>
                    <li>{item.data.id}</li>
                </>
            )
        })