react-responsive-creator v0.1.1
class Test extends Component { constructor(props){ super(props) this.onSearch = this.onSearch.bind(this); console.log(this); }
onSearch(test) {
console.log(test);
}
render(){
/*This is important to show the 2 versions of the component */
return <div>{this.props.children}</div>
}
}
const mapState = state => ({ test:state.test })
const mapDisptach = (dispatch) => ({ testAction: userAgent => {dispatch(testAction(userAgent))} })
export default connect(mapState,mapDisptach)(withResponsive(Test,TestDesktop,TestMobile))
class TestDesktop extends Component{ constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); }
handleClick(){ this.props.testAction(window.navigator.userAgent);//eslint-disable-line } render(){ return ( <div> <span>Desktop</span> <button onClick={this.handleClick}>Test</button> </div> ); } } export default TestDesktop;
class TestMobile extends Component{ constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleClick(){ this.props.testAction(window.navigator.userAgent);//eslint-disable-line } render(){ return ( <div> <span>Mobile</span> <button onClick={this.handleClick}>Test</button> <span>REDUX: {JSON.stringify(this.props.test)}</span> </div> ); } } export default TestMobile;
const test = (state = 0, action) => { switch (action.type) { case 'TEST': return action; default: return state; } };
export default test;