Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 566 | Rev 588 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
561 geraldo 1
import React, { useState, useEffect } from "react";
2
 
3
const Option = (props) => {
4
 
5
    // get props
565 geraldo 6
    const { option } = props;
561 geraldo 7
 
8
    // init States
564 geraldo 9
    const [input, setInput] = useState(option.answer);
561 geraldo 10
 
11
    /**
564 geraldo 12
     * Update option answer
13
     * @param {*} value
561 geraldo 14
     */
15
    const handleAnswer = (value) => {
16
        setInput(value);
564 geraldo 17
        option.answer = value;
561 geraldo 18
    }
19
 
20
    /**
21
     * componentDidMount
22
     */
23
    useEffect(() => {
564 geraldo 24
        setInput(option.answer);
25
    }, [option]);
561 geraldo 26
 
27
 
564 geraldo 28
 
561 geraldo 29
    return (
564 geraldo 30
        <div className="col-md-12 col-sm-12 col-xs-12 np-padding">
31
            <div className="form-group" >
586 geraldo 32
                <div className="title">{option.title}</div>
564 geraldo 33
            </div>
34
            {option.type == 'open' &&
35
                <div className="form-group">
36
                        <textarea
37
                            className="form-control"
38
                            rows="5"
39
                            value={input}
40
                            maxLength='200'
41
                            name={option.id_option}
42
                            onChange={e => handleAnswer(e.target.value)}
561 geraldo 43
                        />
564 geraldo 44
                </div>
45
            }
561 geraldo 46
        </div>
47
    )
48
}
49
 
566 geraldo 50
export default Option;