0
const AnswerGrid = React.createClass({
    getInitialState: function(){
        return {active: null};
    },
    radioClick: function(e){
    this.setState({active: e.target.value});
    },
    render : function(){
        return (
            <li className="answerOption">
                <input type="radio" onChange={this.radioClick} id={this.props.answer.answer_id} className="radioCustomButton" name={this.props.question_id} value={this.props.answer.answer_id}/><br/>
                <label className="radioCustomLabel">{this.props.answer.title}</label>
            </li>   


        );
    }
});

This is my components call AnswerGrid

const QuestionGrid = React.createClass({
    render : function(){
        var rows = [];
        console.log(this.props.active);
        //console.log(this.props.question);
        var question_id = this.props.question.question_id;
        this.props.question.list_answer.map(function(answer){
            rows.push(<AnswerGrid key={answer.answer_id} answer={answer} question_id={question_id} />);
        });
        return (
            <div className="row">
                <div className="col-md-12">
                    <h2 className="question"><b>{this.props.question.question_title}</b></h2>
                    <input type="type" className="rs" name="rs" value={this.props.active} /><br/>
                    <ul className="answerOptions">
                        {rows}
                    </ul>
                    <hr/>
                </div>
            </div>
        );
    }
});

I am using QuestionGrid to display list li with input from AnswerGrid

When i use value={this.props.active} at QuestionGrid , it not working.

Pls help me fix it

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
Jung Sun
  • 11
  • 2
  • 1
    Please check this link https://stackoverflow.com/questions/35800491/how-to-get-values-from-child-components-in-react it may be helpful. – Nisarg Thakkar Jan 22 '18 at 11:33
  • How are you calling QuestionGrid? Are you passing the "active" property? – Aman B Jan 22 '18 at 11:37
  • Possible Duplicate of https://stackoverflow.com/questions/38394015/how-to-pass-data-from-child-component-to-its-parent-in-reactjs/38397755#38397755 – Shubham Khatri Jan 22 '18 at 11:38
  • Also you should read this https://stackoverflow.com/questions/46594900/reactjs-lifting-state-up-vs-keeping-a-local-state/47349693#47349693 – Shubham Khatri Jan 22 '18 at 11:39
  • Update the question showing the code where you are using QuestionGrid component. – nirazlatu Jan 04 '19 at 08:07

0 Answers0