если писать данные в state бессмысленно, то как мне их получить в handleSubmit(e){} при отправке формы?
handleSubmit = e => {
const { postComment, productID, userID, productSlug } = this.props;
const { userName, userEmail, commentContent } = this.state;
if (/* is form valid */) {
postComment({
user_name: userName,
user_email: userEmail,
comment_content: commentContent,
product_id: productID,
product_slug: productSlug,
user_id: userID,
});
}
};
class Example extends React.Component {
state = { value: '' };
componentDidMount() {
this.props.fetchSomeData();
}
handleChange = e => {
const { value } = e.target;
this.setState({ value });
};
handleSubmitButtonClick = () => {
const { value } = this.state;
const { postSomeData } = this.props;
if (value) {
postSomeData({ value });
}
};
render() {
const { data, error, isFetching, fetchSomeData } = this.props;
const { value } = this.state;
if (isFetching) return <Preloader />;
if (error) return <TryAgain error={error} fetch={fetchSomeData} />;
return (
<Wrapper>
{data.map(item => <Item key={item.id} item={item} />)}
<input value={value} onChange={this.handleChange} />
<button onClick={this.handleSubmitButtonClick}>Submit</button>
</Wrapper>
);
}
}
const mapStateToProps = state => ({
data: someDataSelector(state),
isFetching: someDataFetchingStateSelector(state),
error: someDataErrorSelector(state),
});
const mapDispatchToProps = {
fetchSomeData,
postSomeData,
};
export default connect(mapStateToProps, mapDispatchToProps)(Example);
можно конечно сделать запрос еще раз, но зачем?
return (
<Route
key={i}
path={'/account/tickets'}
render={() => <div>Test</div>}
/>
);
'route' { ... }
?
Google Meet