Alex Moldovan
@alexnmoldovan
Organizer @ JSHeroes
Product Engineer @ CodeSandbox
https://slides.com/alexmoldovan/custom-hooks
componentDidMount
useEffect
componentWillUnmount
return from useEffect*
componentWillReceiveProps
function
componentDidUpdate
useEffect with deps
Source: https://reactjs.org/docs/hooks-effect.html
Imperative
Declarative
Imperative
Declarative
Logic
View
Logic
View
Building your own Hooks lets you extract component logic into reusable functions.
Logic
View
JSX function
Custom Hook(s)
import React from 'react';
var MyMixin = {
doSomething() {
}
};
const MyComponent = React.createClass({
mixins: [MyMixin],
handleClick() {
this.doSomething();
},
render() {
return (
<button onClick={this.handleClick}>Do Something</button>
);
}
});
export default MyComponent;
<Provider value="x">
<Layout>
<ComponentA/>
<ComponentB/>
<ComponentC/>
</Layout>
</Provider>
https://github.com/codesandbox/sandpack
Alex Moldovan
@alexnmoldovan
Co-Founder @ JSHeroes
Product Engineer @ CodeSandbox
https://slides.com/alexmoldovan/custom-hooks