0

I've been trying to figure out why renderFilteredList does not render these list items (both of them include the substring this.props.searchedWord and the console logs true, and renderFilteredList is called from the original render function).

{<li key={singleObject.body} className="list-group-item">{singleObject.body}</li>} 
{<li key={singleObject.name} className="list-group-item">{singleObject.name}</li>}

and I couldn't figure out why, can anyone tell me what is wrong with my code please?

renderFilteredList(){
    console.log('the data to fetch is: ', this.props.dataFetched, 'and the searchedWord is: ', this.props.searchedWord);
    return this.props.dataFetched.map(objects=>{
            return objects.map(singleObject=>{
                console.log(singleObject.body.includes(this.props.searchedWord), singleObject.name.includes(this.props.searchedWord));
            <div>
                {<li key={singleObject.body} className="list-group-item">{singleObject.body}</li>}
                {<li key={singleObject.name} className="list-group-item">{singleObject.name}</li>}
                <hr/>
            </div>
             })
    })

1 Answer 1

1

You have to return the <div> within the map function. Right now you are returning nothing.

I'm also just assuming that you are calling this method within the return of your render method. If you are simply calling it but returning nothing from render, you'll still not get anything to the display.

renderFilteredList(){
  console.log('the data to fetch is: ', this.props.dataFetched, 'and the searchedWord is: ', this.props.searchedWord);
  return this.props.dataFetched.map(objects => {
    return objects.map(singleObject => {
      console.log(singleObject.body.includes(this.props.searchedWord), singleObject.name.includes(this.props.searchedWord));
      return (
        <div>
          {<li key={singleObject.body} className="list-group-item">{singleObject.body}</li>}
          {<li key={singleObject.name} className="list-group-item">{singleObject.name}</li>}
          <hr/>
        </div>
      );
    });
  });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.