Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react';
import Progress from 'components/Progress';
import ProgressInput from 'components/ProgressInput';
class App extends Component {
state = {
count: 10
}
onChangeCount = count => {
import React, { Component } from 'react';
import CurrentTime from 'components/CurrentTime';
class CurrentYear extends Component {
render() {
const { time } = this.props;
return <div>{time.getFullYear()}</div>
}
}
import React, { Component, createElement } from 'react';
class CurrentTime extends Component {
state = {
time: new Date()
}
tick = () => {
this.setState({time: new Date()})
}
class ComponentThatsGenerateAValue extends Component {
state = {
value: initialState
}
onChange = newState => {
this.setState({value: newState})
}
render() {
@manoelneto
manoelneto / withRouter.js
Created August 7, 2018 21:46
withRouter.js
export default const withRouter = (OriginalComponent) => {
class NewComponent extends Component {
state = {
router: initialRouter
}
anotherFunc = () => {
...
const myComponent = ({router, anotherFunc}) => {
...
}
export default withRouter(myComponent);
class MyOtherComponent extends Component {
// router e anotherFunc estará disponível dentro de this.props.
componentDidMount() {
this.props.anotherFunc();
}
}
export default withRouter(MyOtherComponent);
@manoelneto
manoelneto / withX.js
Created August 7, 2018 21:49
withX.js
withA(withB(withC(FinalComponent)));
class Router extends Component {
state = {
router: initialRouter
}
render() {
createElement(this.props.component, this.state)
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';
class App extends React.Component {
state = {
editorState: EditorState.createEmpty()
}
onChange = editorState => this.setState({editorState})