Skip to content

Instantly share code, notes, and snippets.

const useStore = (
[state, dispatch],
{ mapStateToProps, mapDispatchToProps, mergeProps },
extraArg
) => {
const stateProps = useMemo(
() => (mapStateToProps != null ? mapStateToProps(state, extraArg) : null),
[mapStateToProps, state, extraArg]
);
const dispatchProps = useMemo(
class Timeout extends React.Component {
static LOADED = 0
static LOADING = 1
static TIMED_OUT = 2
state = { mode: Timeout.LOADED }
componentDidCatch(maybePromise) {
if (!(maybePromise instanceof Promise)) {
const notAPromise = maybePromise
class LoaderWithGame extends React.Component {
state = { isPlaying: false }
startGame = () => this.setState({ isPlaying: true })
endGame = () => this.setState({ isPlaying: false })
render() {
return (
<React.Timeout>
const LoadsUserWithLoadingSpinner = () => (
<React.Timeout ms={300}>
{didTimeout ? (
<p>Loading...</p>
) : (
<UsesData />
)}
</React.Timeout>
)
const fetchUser = createDataFetcher('http://website.com/users/me')
const UsesData = () => {
const user = fetchUser()
return (
<div>
{user.name}
</div>
)
}
const createDataFetcher = (url) => {
let result = null
let promise = null
return () => {
if (result != null) {
return result;
}
if (promise === null) {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!doctype html>
<title>Dropdown</title>
<style>
input {
box-sizing: border-box;
width: 200px;
}
.options {
(function (root, wrapper) {
if (typeof define == "function" && define.amd) define([], function () {
return wrapper;
});else if (typeof module == "object" && module.exports) module.exports = wrapper;else (root.nbind = root.nbind || {}).init = wrapper;
})(this, function (Module, cb) {
if (typeof Module == "function") {
cb = Module;Module = {};
}Module.onRuntimeInitialized = function (init, cb) {
return function () {
if (init) init.apply(this, arguments);try {