This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Layout extends PureComponent{ | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| showModal: false | |
| } | |
| } | |
| toggleModal = () => this.setState({ showsModal: !this.state.showModal }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.state = { | |
| modal1: true, | |
| modal2: false, | |
| modal3: true | |
| } | |
| toggleModal1 = () => this.setState({ modal1: !this.state.modal1 }) | |
| toggleModal2 = () => this.setState({ modal2: !this.state.modal2 }) | |
| toggleModal3 = () => this.setState({ modal3: !this.state.modal3 }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Layout({ showModal, showModalUpdater }) { | |
| // ... | |
| return ( | |
| <Fragment> | |
| //... | |
| <Modal open={showModal}/> | |
| //... | |
| <Button onClick={showModalUpdater}>Open Modal </Button> | |
| </Fragment> | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const withToggle = (initialState = {}) => (BaseComponent) => { | |
| class WithHandlers extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| const initialStateKeys = Object.keys(initialState) | |
| if (initialStateKeys.length) { | |
| this.stateUpdaters = initialStateKeys.reduce((acc, value) => { | |
| acc[`${value}Updater`] = () => (this.setState({ [value]: !this.state[value] })) | |
| return acc | |
| }, {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const {Provider, Consumer} = React.createContext(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App extends Component { | |
| static childContextTypes = { | |
| counter: PropTypes.object | |
| } | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| count: 0, | |
| increment: this.increment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {Component, PureComponent, createContext} from 'react'; | |
| const Context = createContext(); | |
| class User { | |
| constructor(getState, rootUpdater) { | |
| this._getState = getState; | |
| this._rootUpdater = rootUpdater; | |
| this.name = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Store extends Component { | |
| /* | |
| a lot of methods here | |
| */ | |
| render() { | |
| const updaters = {/*methods what*/}; | |
| const data = {/* this.state*/}; | |
| const value = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User { | |
| constructor(getState, rootUpdater) { | |
| this._getState = getState; | |
| this._rootUpdater = rootUpdater; | |
| this.name = ''; | |
| this.surname = ''; | |
| } | |
| _setValue = (value = {}) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Store extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.rootUpdater = (data = {}) => { | |
| this.setState({ | |
| ...this.state, | |
| ...data | |
| }) | |
| }; |
OlderNewer