Question to React.js Specialist
there is a stateless component
import { connect } from 'react-redux'; import { compose, withState, withHandlers, } from 'recompose'; import PropTypes from 'prop-types'; import ColumnPresentation from './ColumnPresentation'; import { setPlayerStep, setWinner } from '../GameState'; export default compose( connect( state => ({ playerStep: state.game.playerStep, winner: state.game.winner, }), dispatch => ({ setPlayerStep: () => dispatch(setPlayerStep()), setWinner: winner => dispatch(setWinner(winner)), }), ), withState('count', 'setCount', 0), withState('arrayFiller', 'setArrayFiller', [...Array(6)]), withHandlers({ incrementCount: props => () => { props.setCount(props.count + 1); }, }), )(ColumnPresentation); import React from 'react'; import Cell from '../../../components/Cell'; function columnPresentation({ arrayFiller, incrementCount, }) { return ( <div> <div onClick={incrementCount} style={{ flexDirection: 'column', display: 'inline-block' }} role="button" tabIndex={0} > <p>Hello</p> </div> </div> ); } export default columnPresentation; How now to multiply this component:
import React from 'react'; import ColumnPresentation from '../column/ColumnPresentationContainer'; function homePresentation() { return ( <div style={styles.container}> <ColumnPresentation /> <ColumnPresentation /> </div> ); } const styles = { container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', }, }; export default homePresentation; What was each had its own state, independent of the others? When I click on one, the state of the second component changes.