SlideShare a Scribd company logo
SUBJECTIVE BEST
PRACTICES FOR REACT
WOJCIECH PIĄTKOWSKI
ARCHITECTURE DOCUMENTATION
▸ explains how to write features
▸ a contract between team
members
▸ unified way of getting pieces
together
▸ discussion about
architecture in one place
▸ newcomers can be quickly
introduced to
ARCHITECTURE DOCUMENTATION
▸ can get outdated easily
▸ it’s a theory
▸ no one really reads it :)
SCAFFOLDING
▸ it’s also a documentation
▸ provides real code that
can be reused very
quickly
Scaffolding Reflux Component
SCAFFOLDING
▸ used often thus it’s likely
to get update when
something changes.
Scaffolding Reflux Component
SCAFFOLDING
▸ you can easily write your own to match often custom needs of a project
▸ or use one of third party projects
Use example of
https://www.npmjs.com/package/react-scaffold
▸ or even fork one of those on
github too much your needs
REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE
D
E
S
T
R
U
C
T
E
D
REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE
D
E
S
T
R
U
C
T
E
D
REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE
NOT
D
E
S
T
R
U
C
T
E
D
SMART AND DUMP COMPONENTS
Smart component
- displays three dump
components
- connects to a store through
this.store = chairsStore
- triggers action
chairActions.createChair
Dump component
- displays simple form
- has no state
SMART AND DUMP COMPONENTS
Smart component
- div’s witch css classes were
added
- css classes holds
presentational function which
belongs to to dump
components
- chairs.css is imported
which adds styles to
elements with css classes
- thanks to it smart
components now holds also
presentational
Let’s delegate presentational
function to somewhere else…
SMART AND DUMP COMPONENTS
Smart component
- It’s previous presentational
features were moved to
ChairsManger
- ChairsManger receives
all it’s content via children
prop …
…which makes wrapping each
child separately very hard
SMART AND DUMP COMPONENTS
Smart component
- all props that previously were
sent to each child dumb
component, are grouped and
passed to ChairsManager
- ChairsManager does all
the presentational work
Making ChairsManager more flexible - #1
SMART AND DUMP COMPONENTS
Dump component
- recevies all props
- passes each prop to specific
child dump component
- there are no unique for
ChairsManager props
- a lot of props are just passed
further, they don’t do real job
here
Making ChairsManager more flexible - #1
SMART AND DUMP COMPONENTS
Smart component
- there are no data passed to
ChairsManager that would
normally be passed to dump
components
- Dump components itself are
passed to ChairsManager
Making ChairsManager more flexible - #2
SMART AND DUMP COMPONENTS
Dump component
- receives props
elements/components
through props
- those props may be
interpreted as slots where
other can components can fit
- there are no „dead” props
Making ChairsManager more flexible - #2
This is simplified example. In
real project structures are more
complicated. General idea is to
avoid having too many props
passes to a component only to
have them passed further.
PRACTICAL TESTING OF REACT COMPONENTS
Deep snapshot testing
- those test are super simple to
write
- thanks to scaffolding they
may require zero effort
- they don’t test behavior
- rather than that they are
freezing already working
component
- when any of its children is
changed the snapshot test
will alert us
- action can be taken if
necessary or simply quick
update of snapshot test
STYLES ENCAPSULATIONS
- globals styles should be
avoided
- styles can be easily
encapsulated with a css
class specific to a component
- effort of creating a new style
file for each component can
be minimized thanks to
scaffolding
- minimizes chances of styles
collision (some extra
strategies can be added like
project related prefixes)
- keep styling close to related
component - easier to
maintain
ComponentName.less
HOT MODULE RELOADING + REACT
- Working with minimalistic
source maps - eval
- faster bundling
- no problems with source
maps while using HMR
- target of babel transpiration
does not have to be ES5
which means even faster
bundling
- http://kangax.github.io/compa
t-table/es2016plus/
support of ES2016+ is great!
- babel-preset-env picks
minimal number of
transformers base on
specified target, e.g chrome
v61
- dev: ‚eval’
thanks to that modules are
displayed with generated
code which is close to ES6+
HOT MODULE RELOADING + REACT
- code is ES2016+ without
classes
- of course no JSX
- but the code is in general
readable
- and probably sooner or later
it will be possible not to
transform ES6 classes
HOT MODULE RELOADING + REACT
- unfortunately due to possible
bug in react-hot-loader
transformation of ES6
classes is necessary
- react-hot-loader
currency is in beta version:
3.0.0-beta.7
what gives hope that problem
soon will be solved
LAST WORDS - LINTING
▸ the sooner it’s set up the better
▸ introducing some of useful linters rules in late phase of the project is either impossible or very hard to do
so
▸ for those rules which does not support —fix it’s still possible to automize thanks to additional transformers
e.g. ESLints’s rule sort-comp has a separate transformer in react-codemod
▸ configuration of ESlint can be
accelerated by picking one of
already prepared config, e.g.
eslint-config-airbnb,
eslint-config-eslint
The full list of most popular configs
can be found at Github:
dustinspecker/awesome-eslint
ITea&Coffee: React best practices

More Related Content

What's hot (20)

PPTX
Continuous deployment of Rails apps on AWS OpsWorks
Tomaž Zaman
 
PPTX
Serverless meetup - OpenWhisk overview and architecture
Sandeep Paliwal
 
PDF
PuppetConf 2016: Keynote: Pulling the Strings to Containerize Your Life - Sco...
Puppet
 
PDF
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
Tikal Knowledge
 
PPTX
Multi-stage Docker builds to make building easy!
Milindu Sanoj Kumarage
 
PPTX
An introduction to Atlassian Bitbucket Pipelines
Dave Clark
 
PPTX
Managing short lived Kubernetes (Production) deployments
Haufe-Lexware GmbH & Co KG
 
PPTX
Continuous integration of_puppet_code
Devoteam Revolve
 
PPTX
AWS CodeDeploy - basic intro
Anton Babenko
 
PDF
Beginner's Guide to Angular 2.0
All Things Open
 
PPTX
Serverless Cron Jobs with Ruby on Jets
Tung Nguyen
 
PDF
Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
Serverless User Group Poland
 
PDF
Serverless
Maciej Dziergwa
 
PPTX
Using Docker in Production
CloudHero
 
PPTX
Continuous integration using atlassian bamboo
Alexander Masalov
 
PPTX
How Docker simplifies CI/CD
Gabriel N. Schenker
 
PDF
Grunt training deck
James Ford
 
PPTX
Modern Tools for Building Progressive Web Apps
All Things Open
 
PPTX
Puppetcamp r10kyaml
Puppet
 
PPTX
Concurrent Rendering Adventures in React 18
Maurice De Beijer [MVP]
 
Continuous deployment of Rails apps on AWS OpsWorks
Tomaž Zaman
 
Serverless meetup - OpenWhisk overview and architecture
Sandeep Paliwal
 
PuppetConf 2016: Keynote: Pulling the Strings to Containerize Your Life - Sco...
Puppet
 
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
Tikal Knowledge
 
Multi-stage Docker builds to make building easy!
Milindu Sanoj Kumarage
 
An introduction to Atlassian Bitbucket Pipelines
Dave Clark
 
Managing short lived Kubernetes (Production) deployments
Haufe-Lexware GmbH & Co KG
 
Continuous integration of_puppet_code
Devoteam Revolve
 
AWS CodeDeploy - basic intro
Anton Babenko
 
Beginner's Guide to Angular 2.0
All Things Open
 
Serverless Cron Jobs with Ruby on Jets
Tung Nguyen
 
Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
Serverless User Group Poland
 
Serverless
Maciej Dziergwa
 
Using Docker in Production
CloudHero
 
Continuous integration using atlassian bamboo
Alexander Masalov
 
How Docker simplifies CI/CD
Gabriel N. Schenker
 
Grunt training deck
James Ford
 
Modern Tools for Building Progressive Web Apps
All Things Open
 
Puppetcamp r10kyaml
Puppet
 
Concurrent Rendering Adventures in React 18
Maurice De Beijer [MVP]
 

Similar to ITea&Coffee: React best practices (20)

PPTX
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
Alexander Dean
 
PDF
Dockercon EU 2014
Rafe Colton
 
PPTX
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
Docker, Inc.
 
PPT
Migraine Drupal - syncing your staging and live sites
drupalindia
 
PPTX
Webpack essentails - feb 19, 2020
Jesse Colligan
 
PDF
Docker Online Meetup #3: Docker in Production
Docker, Inc.
 
PDF
Why you should consider a microframework for your next web project
Joaquín Muñoz M.
 
PDF
Transformative Git Practices
Nicola Paolucci
 
PDF
Docker 102 - Immutable Infrastructure
Adrian Otto
 
PDF
Webpack: from 0 to 2
Alessandro Bellini
 
PDF
SCSS Styleguide
Karthikeyan Rajendran
 
PDF
Serverless in production, an experience report (IWOMM)
Yan Cui
 
PPTX
Reuse, Reduce, Recycle in Serverless World
Dmitri Zimine
 
PDF
Shipping NodeJS with Docker and CoreOS
Ross Kukulinski
 
PPTX
Onion Architecture with S#arp
Gary Pedretti
 
PDF
InfluxCloudi craft container orchestrator
Gianluca Arbezzano
 
PDF
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 
PDF
Kash Kubernetified
Michael Wojcikiewicz
 
PDF
FireWorks overview
Anubhav Jain
 
PPT
Maven: Managing Software Projects for Repeatable Results
Steve Keener
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
Alexander Dean
 
Dockercon EU 2014
Rafe Colton
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
Docker, Inc.
 
Migraine Drupal - syncing your staging and live sites
drupalindia
 
Webpack essentails - feb 19, 2020
Jesse Colligan
 
Docker Online Meetup #3: Docker in Production
Docker, Inc.
 
Why you should consider a microframework for your next web project
Joaquín Muñoz M.
 
Transformative Git Practices
Nicola Paolucci
 
Docker 102 - Immutable Infrastructure
Adrian Otto
 
Webpack: from 0 to 2
Alessandro Bellini
 
SCSS Styleguide
Karthikeyan Rajendran
 
Serverless in production, an experience report (IWOMM)
Yan Cui
 
Reuse, Reduce, Recycle in Serverless World
Dmitri Zimine
 
Shipping NodeJS with Docker and CoreOS
Ross Kukulinski
 
Onion Architecture with S#arp
Gary Pedretti
 
InfluxCloudi craft container orchestrator
Gianluca Arbezzano
 
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 
Kash Kubernetified
Michael Wojcikiewicz
 
FireWorks overview
Anubhav Jain
 
Maven: Managing Software Projects for Repeatable Results
Steve Keener
 
Ad

Recently uploaded (20)

PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Ad

ITea&Coffee: React best practices

  • 1. SUBJECTIVE BEST PRACTICES FOR REACT WOJCIECH PIĄTKOWSKI
  • 2. ARCHITECTURE DOCUMENTATION ▸ explains how to write features ▸ a contract between team members ▸ unified way of getting pieces together ▸ discussion about architecture in one place ▸ newcomers can be quickly introduced to
  • 3. ARCHITECTURE DOCUMENTATION ▸ can get outdated easily ▸ it’s a theory ▸ no one really reads it :)
  • 4. SCAFFOLDING ▸ it’s also a documentation ▸ provides real code that can be reused very quickly Scaffolding Reflux Component
  • 5. SCAFFOLDING ▸ used often thus it’s likely to get update when something changes. Scaffolding Reflux Component
  • 6. SCAFFOLDING ▸ you can easily write your own to match often custom needs of a project ▸ or use one of third party projects Use example of https://www.npmjs.com/package/react-scaffold ▸ or even fork one of those on github too much your needs
  • 7. REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE D E S T R U C T E D
  • 8. REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE D E S T R U C T E D
  • 9. REACT COMPONENTS CLEARNESS - DESTRUCTING PROPS AND STATE NOT D E S T R U C T E D
  • 10. SMART AND DUMP COMPONENTS Smart component - displays three dump components - connects to a store through this.store = chairsStore - triggers action chairActions.createChair Dump component - displays simple form - has no state
  • 11. SMART AND DUMP COMPONENTS Smart component - div’s witch css classes were added - css classes holds presentational function which belongs to to dump components - chairs.css is imported which adds styles to elements with css classes - thanks to it smart components now holds also presentational Let’s delegate presentational function to somewhere else…
  • 12. SMART AND DUMP COMPONENTS Smart component - It’s previous presentational features were moved to ChairsManger - ChairsManger receives all it’s content via children prop … …which makes wrapping each child separately very hard
  • 13. SMART AND DUMP COMPONENTS Smart component - all props that previously were sent to each child dumb component, are grouped and passed to ChairsManager - ChairsManager does all the presentational work Making ChairsManager more flexible - #1
  • 14. SMART AND DUMP COMPONENTS Dump component - recevies all props - passes each prop to specific child dump component - there are no unique for ChairsManager props - a lot of props are just passed further, they don’t do real job here Making ChairsManager more flexible - #1
  • 15. SMART AND DUMP COMPONENTS Smart component - there are no data passed to ChairsManager that would normally be passed to dump components - Dump components itself are passed to ChairsManager Making ChairsManager more flexible - #2
  • 16. SMART AND DUMP COMPONENTS Dump component - receives props elements/components through props - those props may be interpreted as slots where other can components can fit - there are no „dead” props Making ChairsManager more flexible - #2 This is simplified example. In real project structures are more complicated. General idea is to avoid having too many props passes to a component only to have them passed further.
  • 17. PRACTICAL TESTING OF REACT COMPONENTS Deep snapshot testing - those test are super simple to write - thanks to scaffolding they may require zero effort - they don’t test behavior - rather than that they are freezing already working component - when any of its children is changed the snapshot test will alert us - action can be taken if necessary or simply quick update of snapshot test
  • 18. STYLES ENCAPSULATIONS - globals styles should be avoided - styles can be easily encapsulated with a css class specific to a component - effort of creating a new style file for each component can be minimized thanks to scaffolding - minimizes chances of styles collision (some extra strategies can be added like project related prefixes) - keep styling close to related component - easier to maintain ComponentName.less
  • 19. HOT MODULE RELOADING + REACT - Working with minimalistic source maps - eval - faster bundling - no problems with source maps while using HMR - target of babel transpiration does not have to be ES5 which means even faster bundling - http://kangax.github.io/compa t-table/es2016plus/ support of ES2016+ is great! - babel-preset-env picks minimal number of transformers base on specified target, e.g chrome v61 - dev: ‚eval’ thanks to that modules are displayed with generated code which is close to ES6+
  • 20. HOT MODULE RELOADING + REACT - code is ES2016+ without classes - of course no JSX - but the code is in general readable - and probably sooner or later it will be possible not to transform ES6 classes
  • 21. HOT MODULE RELOADING + REACT - unfortunately due to possible bug in react-hot-loader transformation of ES6 classes is necessary - react-hot-loader currency is in beta version: 3.0.0-beta.7 what gives hope that problem soon will be solved
  • 22. LAST WORDS - LINTING ▸ the sooner it’s set up the better ▸ introducing some of useful linters rules in late phase of the project is either impossible or very hard to do so ▸ for those rules which does not support —fix it’s still possible to automize thanks to additional transformers e.g. ESLints’s rule sort-comp has a separate transformer in react-codemod ▸ configuration of ESlint can be accelerated by picking one of already prepared config, e.g. eslint-config-airbnb, eslint-config-eslint The full list of most popular configs can be found at Github: dustinspecker/awesome-eslint