Hi πΒ
My name is Alex, nice to see you!
Alex Moldovan
@alexnmoldovan
Organizer @ JSHeroes
Product Engineer @ CodeSandbox
https://slides.com/alexmoldovan/custom-hooks
π₯
π
π
Lifecycle as hooks
componentDidMount
useEffect
componentWillUnmount
return from useEffect*
componentWillReceiveProps
function
componentDidUpdate
useEffect with deps
π
> sync nature of useEffect
> rules of hooks
> list of dependencies
> callback functions inside functions
π
π€
Source: https://reactjs.org/docs/hooks-effect.html
Imperative
Declarative
π€
Mindset change: separation of concerns
Show me the code!
π€
π
Imperative
Declarative
π
Logic
View
π
Logic
View
π
π
Custom Hooks
Building your own Hooks lets you extract component logic into reusable functions.
π
Show me the code!
π
Logic
View
JSX function
Custom Hook(s)
π
π
π
π
Show me the code!
π€
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;
π€
Adding context to the mix
π
<Provider value="x">
<Layout>
<ComponentA/>
<ComponentB/>
<ComponentC/>
</Layout>
</Provider>
Provide
Consume
π
π
π
https://github.com/codesandbox/sandpack
Show me the code!
π
π
Thank you πΒ Questions?
Alex Moldovan
@alexnmoldovan
Co-Founder @ JSHeroes
Product Engineer @ CodeSandbox
https://slides.com/alexmoldovan/custom-hooks
My love-hate relationship with hooks
By Alex Moldovan
My love-hate relationship with hooks
- 579