R
R
rsoinvi2018-06-21 15:53:47
React
rsoinvi, 2018-06-21 15:53:47

How to pass input value to dispatch?

How to pass input values ​​to dispatch?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Antonov, 2018-06-21
@rsoinvi

Probably something like this .. too little data in the question)

class SomeComponent extends Component {
    static propTypes = {
        someFunction: PropTypes.func
    }
    state = {
        inputValue: transferTemplateType.none,
    }
    handleChangeTextInput = (event) => {
        this.setState({ [event.target.name]: event.target.value });
    }
    sendValue = () => {
        this.props.someFunction(this.state.inputValue);
    }

    render() {
        return (
            <div>
                <input onChange={this.handleChangeTextInput} value={this.state.inputValue} />
                <button onclick={this.sendValue}>Передать значение</button>
            </div >
        );
    }
}


const mapDispatchToProps = (dispatch) => ({
    someFunction: (inputValue) => dispatch(someFunction(inputValue))
});

export default connect(null, mapDispatchToProps)(SomeComponent);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question