Answer the question
In order to leave comments, you need to log in
How to add filter to react in conjunction with map?
there is a code that displays 6 jokes. question-answer format
How to add a filter by removing the question from the output, if the length of the question is more than 50 characters.
I've tried something like .filter(joke => joke.question < 50) and stuff like that, but it gives me a blank page or errors. I'm obviously missing something.
function App() {
const jokeComponents = jokesData
// единственный фильтр который у меня получилось добавить :( = c ним будет 3 шутки выводится.
.filter(joke => joke.id <= jokesData.length-3)
// если выводить сначала map, а после filter будет белая страница, тоже интересно было бы знать почему так?
.map(joke => <Joke key={joke.id} question={joke.question} punchLine={joke.punchLine} />)
return (
<div>
{jokeComponents}
</div>
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question