Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 597 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useState, useEffect } from "react";

const Option = (props) => {

    // get props
    const { option } = props;

    // init States 
    const [input, setInput] = useState(option.answer);

    /**
     * Update option answer
     * @param {*} value
     */
    const handleAnswer = (value) => {
        setInput(value);
        option.answer = value;
    }

    /**
     * componentDidMount
     */
    useEffect(() => {
        setInput(option.answer);
    }, [option]);



    return (
        <div className="col-md-12 col-sm-12 col-xs-12 np-padding mb10">
            <div className="form-group" >
                <div className="title">
                    <h6 className="opt-h6">{option.title}:</h6>
                </div>
            </div>
            <div className="form-group">
                <textarea
                    className="form-control"
                    rows="5"
                    value={input}
                    maxLength='200'
                    name={option.id_option}
                    onChange={e => handleAnswer(e.target.value)}
                />
            </div>
        </div>
    )
}

export default Option;