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

Good practices ini React & functional prog.

Juan Roa
February 29, 2020

Good practices ini React & functional prog.

Juan Roa

February 29, 2020
Tweet

More Decks by Juan Roa

Other Decks in Programming

Transcript

  1. Who am I? • Full-stack engineer at Bunny Studio Inc.

    • Open source & communities supporter • Cat lover (I have 6 cats!) • Organizer & Coach at Rails Girls Cali • React & React Native coach • I’m also a Bitcoin/Crypto enthusiast • Love mountain biking
  2. Functional programming? Programming paradigm which has its roots in math.

    It aims to avoid the problems that come with: • shared state • mutable data • side effects which are common in object oriented programming (OOP).
  3. Given the same inputs, it always returns the same output

    and it has not side effects Side effects?
  4. Some commonly used Mutate functions in JS • copyWithin •

    fill • pop • push • reverse • shift • sort • splice • Unshift https://doesitmutate.xyz/
  5. Your best friends :D • concat • split • join

    • map • reduce • filter • find • findIndex • Object.assign ***
  6. Best practices in React • Keep your code as cleaner

    as possible • DRY / Try to make you components reusable • Avoid too much logic within components • Use helper functions everytime, everywhere • ALWAYS use propTypes or similar (if using TS/Flow) • Try hooks, they tend to make your code smaller and less complex • Try to avoid using getDerivedStateFromProps • Use conditional assignment to avoid mutations • Split responsibilities • Migrate your deprecated lifecycle methods • Do not overload your useEffect / componentDidMount methods
  7. Homework Try to identify mutations and overload functions in your

    components and Support local communities !