Answer the question
In order to leave comments, you need to log in
How to work with data from query?
There is a FAQ page, respectively, there is a list of questions, by clicking on the question the answer should open. Previously, it was done like this, there was a function that, when clicked, passed the index of the question on which the click was made, was shown in the answer. if there was a second click on the same question, then the question index was removed from the state and the answer was hidden.
class Questions extends PureComponent {
constructor(...args) {
super(...args);
this.handleOnSelectQuestion = ::this.handleOnSelectQuestion;
this.state = {
selectQuestion: [],
}}
handleOnSelectQuestion(question) {
this.setState(({selectQuestion}) => {
if(selectQuestion.indexOf(question) > -1){
return {
selectQuestion: selectQuestion.filter(questionId => questionId !== question)
};
}
return {
selectQuestion: [... selectQuestion, question]
};
});
}
}
render() {
return(
<div className={styles.question_container}>
{questionsList.map((question, index) => (
<QuestionsCard
key={index}
title={question.question}
answer={question.answer}
onSelect={partial(this.handleOnSelectQuestion, index)}
isOpen={selectQuestion.indexOf(index) > -1}
index={index}
/>
)
)}
</div>
)
}
const {location} = this.props;
const query = {...location.query, question: [...location.query.question, question]};
Answer the question
In order to leave comments, you need to log in
The utility you use to parse query string returns values as strings. Which is obvious.
What is the question, exactly? Don't know how to cast string to number ?
It is possible like this:
const string = '1';
const number = Number.parseInt(string);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question