npm i THIS_URL
| import { useState, useEffect, useCallback } from 'react' | |
| function usePromise(createPromise) { | |
| const [error, setError] = useState() | |
| const [value, setValue] = useState() | |
| useEffect(() => { | |
| let current = true | |
| createPromise().then( |
| let UserContext = React.createContext(); | |
| class App extends React.Component { | |
| state = { | |
| user: null, | |
| setUser: user => { | |
| this.setState({ user }); | |
| } | |
| }; |
Note:
When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.
If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:
- Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
This content moved here: https://exploringjs.com/impatient-js/ch_arrays.html#quickref-arrays
| import React from 'react'; | |
| function onlyChild(children) { | |
| return Array.isArray(children) ? children[0] : children; | |
| } | |
| export function combineContext(contexts) { | |
| class Provider extends React.Component { | |
| render() { | |
| const init = this.props.children; |
I started using React 3.5 years ago, and I still love it. It was such a well-designed solution that not much has changed since then, only superficial stuff like naming. What I learned then is still wholly applicable today because it's such a good idea (although now you can choose from many other libraries). On top of that, we now benefit from an entirely new architecture (fiber) without changing much.
| const some_module = require('some_module') | |
| /** | |
| * require('some_module') calls Module._load | |
| * | |
| * Module._load then tries to load the module with a filename (also save it to the cache) using module.load(filename) | |
| * | |
| * module.load(filename), given a filename, passes it to the proper extension handler ('.js', '.json') | |
| * | |
| * If there were any errors when loading the file, it deletes the file from the cache (delete Module._cache[filename]) and throws an error |