Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React - Back to the Future

React - Back to the Future

An overview of ReactJS new and upcoming features, including Lazy loading, data fetching, concurrent rendering and of course - hooks.

Avatar for adam klein

adam klein

January 30, 2019
Tweet

More Decks by adam klein

Other Decks in Programming

Transcript

  1. 22 Redux Hook Libraries redux-hooks react-hooks-redux react-hook-redux redux-react-hook redux-react-hooks react-redux-hooks

    react-redux-hook hook-redux redux-hook react-use-redux use-store react-hooks-easy-redux use-redux react-usemiddleware react-use-dux react-redux-peach hux rehux redux-hooker rehooker
  2. class Counter extends React.Component { state = { count: 1

    }; render() { return ( <button onClick={() => this.setState({ count: this.state.count + 1 })}> { this.state.count } </button> ); } } State - Classes
  3. class Counter extends React.Component { state = { count: 1

    }; render() { return ( <button onClick={() => this.setState({ count: this.state.count + 1 })}> { this.state.count } </button> ); } } State - Classes
  4. class Counter extends React.Component { state = { count: 1

    }; render() { return ( <button onClick={() => this.setState({ count: this.state.count + 1 })}> { this.state.count } </button> ); } } State - Classes
  5. const Counter = () => { const [count, setCount] =

    useState(1); return ( <button onClick={() => setCount(count + 1)}> { count } </button>; ) } State - Hooks
  6. const Counter = () => { const [count, setCount] =

    useState(1); return ( <button onClick={() => setCount(count + 1)}> { count } </button>; ) } State - Hooks
  7. const Counter = () => { const [count, setCount] =

    useState(1); return ( <button onClick={() => setCount(count + 1)}> { count } </button>; ) } State - Hooks
  8. const Counter = () => { const [count, setCount] =

    useState(1); return ( <button onClick={() => setCount(count + 1)}> { count } </button>; ) } State - Hooks
  9. const Counter = () => { const [count, setCount] =

    useState(1); const [value, setValue] = useState(‘’); return ( <button onClick={() => setCount(count + 1)}>{ count } </button>; ) } State - Hooks
  10. const Counter = () => { const [count, setCount] =

    useState(1); const [value, setValue] = useState(‘’); return ( <button onClick={() => setCount(count + 1)}>{ count } </button>; ) } State - Hooks
  11. Separation of Concerns useEffect(() => { // listen to window

    resize }, []); useEffect(() => { // fetch data from API }, [id]);
  12. function useCurrentWidth() { const [width, setWidth] = useState( () =>

    document.body.clientWidth ); const resize = () => { setWidth(document.body.clientWidth); } useEffect(() => { window.addEventListener('resize', resize); return () => window.removeEventListener('resize', resize); }, []); return width; }
  13. function useCurrentWidth() { const [width, setWidth] = useState( () =>

    document.body.clientWidth ); const resize = () => { setWidth(document.body.clientWidth); } useEffect(() => { window.addEventListener('resize', resize); return () => window.removeEventListener('resize', resize); }, []); return width; }
  14. function useCurrentWidth() { const [width, setWidth] = useState( () =>

    document.body.clientWidth ); const resize = () => { setWidth(document.body.clientWidth); } useEffect(() => { window.addEventListener('resize', resize); return () => window.removeEventListener('resize', resize); }, []); return width; }
  15. function useCurrentWidth() { const [width, setWidth] = useState( () =>

    document.body.clientWidth ); const resize = () => { setWidth(document.body.clientWidth); } useEffect(() => { window.addEventListener('resize', resize); return () => window.removeEventListener('resize', resize); }, []); return width; }
  16. const MyComp = () => { const user = useCurrentUser();

    return <span>{ user.name }</span>; }
  17. Component1 State Current Cell Count1 Count2 const [count, setCount] =

    useState(1); const [count2, setCount2] = useState(1); Current Component
  18. const [count, setCount] = useState(1); const [count2, setCount2] = useState(1);

    Component1 State Current Cell Count1 Count2 Current Component
  19. const [count, setCount] = useState(1); const [count2, setCount2] = useState(1);

    Component1 State Current Cell Count1 Count2 Current Component
  20. Conditionals Component1 State Current Cell Count1 Count2 const [count, setCount]

    = useState(1); if (count === 0) { const [count2, setCount2] = useState(1); } const [count3, setCount3] = useState(1); Count3
  21. Component1 State Current Cell Count1 Count2 const [count, setCount] =

    useState(1); if (count === 0) { const [count2, setCount2] = useState(1); } const [count3, setCount3] = useState(1); Count3 Conditionals
  22. Component1 State Current Cell Count1 Count2 Count3 const [count, setCount]

    = useState(1); if (count === 0) { const [count2, setCount2] = useState(1); } const [count3, setCount3] = useState(1); Conditionals
  23. Component1 State Current Cell Count1 Count2 const [count, setCount] =

    useState(1); if (count === 0) { const [count2, setCount2] = useState(1); } const [count3, setCount3] = useState(1); Count3 Conditionals
  24. Rules of Hooks •Must be used in the same order

    •No conditionals, no loops •Must be called at top level •Must be called from a functional component
  25. React Roadmap • Suspense for Code Splitting - Already Shipped

    16.6 with • React Hooks - ~Q1 2019 • Concurrent Mode - ~Q2 2019 • Suspense for Data Fetching - ~mid 2019 • All minor releases