Skip to content

Instantly share code, notes, and snippets.

View Palatnyi's full-sized avatar
🐏
Out sick

Andrew Palatnyi

🐏
Out sick
View GitHub Profile
class Layout extends PureComponent{
constructor(props) {
super(props)
this.state = {
showModal: false
}
}
toggleModal = () => this.setState({ showsModal: !this.state.showModal })
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 })
const Layout({ showModal, showModalUpdater }) {
// ...
return (
<Fragment>
//...
<Modal open={showModal}/>
//...
<Button onClick={showModalUpdater}>Open Modal </Button>
</Fragment>
)
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
}, {})
const {Provider, Consumer} = React.createContext();
class App extends Component {
static childContextTypes = {
counter: PropTypes.object
}
constructor(props) {
super(props);
this.state = {
count: 0,
increment: this.increment
import React, {Component, PureComponent, createContext} from 'react';
const Context = createContext();
class User {
constructor(getState, rootUpdater) {
this._getState = getState;
this._rootUpdater = rootUpdater;
this.name = '';
class Store extends Component {
/*
a lot of methods here
*/
render() {
const updaters = {/*methods what*/};
const data = {/* this.state*/};
const value = {
class User {
constructor(getState, rootUpdater) {
this._getState = getState;
this._rootUpdater = rootUpdater;
this.name = '';
this.surname = '';
}
_setValue = (value = {}) => {
class Store extends Component {
constructor(props) {
super(props);
this.rootUpdater = (data = {}) => {
this.setState({
...this.state,
...data
})
};