Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // actions.js
- function searchAction(search_string) {
- return {
- type: 'SEARCH_SMTH',
- payload: search_string
- }
- }
- // {your component}.js
- // ....
- import { bindActionCreators } from 'redux'
- // ....
- import * as MyActions from "../actions.js";
- // ....
- class YourComponent extends Component {
- constructor(props) {
- super(props);
- this.state = {
- value: ""
- }
- }
- handleChange(event) {
- this.setState({value: event.target.value});
- }
- onSearch() {
- this.props.myActions.searchAction(this.state.value)
- }
- render() {
- return (
- // тут форма
- <input type="text" value={this.state.value} onChange={this.handleChange} />
- <button onClick={this.onSearch}>Найти</button>
- );
- }
- }
- function mapDispatchToProps(dispatch) {
- return {
- myActions: bindActionCreators(MyActions, dispatch),
- }
- }
- function mapStateToProps( state ) {
- return {};
- }
- export default connect(mapStateToProps, mapDispatchToProps)(YourComponent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement