// Lib
import React, {Component} from 'react';

import {InputText} from '../../Form';

export default class String extends Component {

    constructor(props) {
        super(props);
        this.refInp = React.createRef();
    }

    componentWillUnmount() {
        if(this.props.rmSave) {
            this.props.rmSave(this.props.name);
        }
    }

    componentDidMount() {
        if(this.props.addSave) {
            this.props.addSave(this.props.name, () => {
                return this.refInp.current.value;
            });
        }
    }

    render() {
        return (
            <InputText
                data-name={this.props.name}
                type='text'
                defaultValue={this.props.data}
                ref={this.refInp}
            />
        );
    };
}