This file contains 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 } from "react"; | |
class MyComponent extends Component { | |
state = { | |
data: [], | |
error: null, | |
}; | |
handleOnClick = () => | |
fetchData() |
This file contains 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
export const cancellablePromise = promise => { | |
let isCanceled = false; | |
const wrappedPromise = new Promise((resolve, reject) => { | |
promise.then( | |
value => (isCanceled ? reject({ isCanceled, value }) : resolve(value)), | |
error => reject({ isCanceled, error }), | |
); | |
}); |
This file contains 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 } from "react"; | |
import cancelablePromise from "./cancelable-promise"; | |
class MyComponent extends Component { | |
state = { | |
data: [], | |
error: null, | |
}; | |
pendingPromises = []; |
This file contains 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 } from "react"; | |
class CustomComponent extends Component { | |
apiMethod() { /* ... */ } | |
} | |
class ParentComponent extends Component { | |
handleClick = () => this.component.apiMethod(); | |
render() { |
This file contains 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 } from "react"; | |
class CustomComponent extends Component { | |
apiMethod() { /* ... */ } | |
}; | |
const StyledCustomComponent = props => ( | |
<CustomComponent {...props} style={{ padding: 10 }} /> | |
); |
This file contains 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 } from "react"; | |
class CustomComponent extends Component { | |
apiMethod() { /* ... */ } | |
} | |
const StyledCustomComponent = props => ( | |
<CustomComponent | |
ref={props.componentRef} | |
{...props} |
This file contains 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 } from "react"; | |
class CustomComponent extends Component { | |
apiMethod() { /* ... */ } | |
} | |
class StyledCustomComponent extends Component { | |
apiMethod() { | |
this.wrappedComponent.apiMethod(); | |
} |
This file contains 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 } from "react"; | |
class CustomComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.innerRef = props.innerRef || (() => null); | |
} | |
componentDidMount = () => { | |
this.innerRef(this); |
This file contains 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} from "react"; | |
import translations from "./translations"; | |
class LocaleProvider extends Component { | |
state = { locale: "es" }; | |
// Defines the Context that React should | |
// pass down to any component in the subtree | |
getChildContext() { | |
return { |
This file contains 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} from "react"; | |
// Create the LocaleContext with a default value | |
const LocaleContext = React.createContext({ locale: "en", changeLocale: () => null }); | |
class LocaleProvider extends Component { | |
state = { locale: "es" }; | |
render() { | |
const value = { |
OlderNewer