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

React's Equipment System - Higher-Order Component | ReactJS Norway

React's Equipment System - Higher-Order Component | ReactJS Norway

In this talk, it was discussed how to use Higher Order Components to keep your React applications organized, well-structured and maintainable. Oussama was also talking about how pure functions keep code clean and how these same principles can be applied to React components.

Presenter: Oussama Zaki
=====================================================

Follow us

- ReactJS Norway's site: http://bit.ly/2ka4hC8 

- Facebook: http://bit.ly/2kxmHxW 

- Instagram: http://bit.ly/2kpysnJ 

- Twitter: http://bit.ly/2kaehvl 

- Youtube: https://youtu.be/3kAu4Nbo6oE 

Sponsored by Stooic Labs (http://bit.ly/2oTE4dF)
Organizer: Domenico Solazzo (http://bit.ly/2jRxj8j)

ReactJS Norway

April 19, 2018
Tweet

More Decks by ReactJS Norway

Other Decks in Programming

Transcript

  1. export function Loader(props) { if (!props.showLoader) { return null; }

    return ( <div> <div className="loader"></div> <p>{props.message}</p> </div> ); }
  2. export function Alert(props) { if (!props.showAlert) { return null; }

    return ( <div className={props.type}> <h3>{props.title}</h3> </div> ); }
  3. “ A higher-order component is a function that takes a

    component as an input and returns an enhanced version of it. “
  4. function square(number) { return number * number; } var square

    = function (number) { return number * number; }; array.map(square); var squareWrapper = function () { console.log('Returning a function'); return (number) => number * number; };
  5. function square(number) { return number * number; } var square

    = function (number) { return number * number; }; array.map(square); var squareWrapper = function () { console.log('Returning a function'); return (number) => number * number; };
  6. function square(number) { return number * number; } var square

    = function (number) { return number * number; }; array.map(square); var squareWrapper = function () { console.log('Returning a function'); return (number) => number * number; };
  7. function square(number) { return number * number; } var square

    = function (number) { return number * number; }; array.map(square); var squareWrapper = function () { console.log('Returning a function'); return (number) => number * number; };
  8. const a = () => { return ... } const

    b = () => { return () => { return ... } } const b = () => () => {}
  9. const a = () => { return ... } const

    b = () => { return () => { return ... } } const b = () => () => {}
  10. const a = () => { return ... } const

    b = () => { return () => { return ... } } const b = () => () => {}
  11. const a = () => { return ... } const

    b = () => { return () => { return ... } } const b = () => () => {} const bs = () => () => () => () => {}
  12. const number = 15; const increment = num => num

    + 1; const decrement = num => num - 1; const double = num => num * 2; const operation = increment(decrement(double(number)));
  13. Do

  14. render() { const { enhanceProp, ...passThroughProps } = this.props; const

    injectedProp = someStateOrInstanceMethod; // Pass props to wrapped component return ( <WrappedComponent injectedProp={injectedProp} {...passThroughProps} /> ); }