8 things to learn in React before using Redux

  • A component can manage a whole lot of state, pass it down as props to its child components and pass a couple of functions along the way to enable child components to alter the state in the parent component again.
  • Component A is the only component that manages local state but passes it down to its child components as props.
  • In addition, it passes down the necessary functions to enable B and C to alter its own state in A.

    Now, half of the local state of component A is consumed as props by component C but not by component B.

  • When you lift the local state management down to component C, all the necessary props don’t need to traverse down the whole component tree.
  • When a library such as Redux “connects” its state managements layer with React’s view layer, you will often run into a higher order component that takes care of it (connect HOC in react-redux).

Facts about React that should be known before using Redux (or MobX). Most important: Learn React first, then opt-in Redux…
Continue reading “8 things to learn in React before using Redux”

How to Lazy Load features using React and Webpack – codeburst

How to Lazy Load features using #ReactJS and #Webpack:  by @notgiorgi

  • We don’t want to load our app’s whole component library when user enters our site.
  • We need to load components on demand, and after initial load, cache them in the memory for further use.Also we want lazy loading logic to be separated from the component implementations.We can solve this problem using Webpack import functions and Higher order components.Our HOC takes two arguments, second is the component which will be shown while component is loading, because we don’t want our users to be looking at the blank screen.First argument is the getComponent function, this is where we call Webpack import:One might ask why we don’t pass the path directly to the HOC.
  • E.g. if we do something like this: Webpack will bundle all the files in the .
  • If we pass the whole string directly import(‘.
  • But we cannot do this: path = import(path), because Webpack won’t know which files to consider, it won’t have any pattern to match files against.So our HOC, calls import before it mounts and displays the spinner while component is being downloaded.This way we can easily convert any statically imported component into lazy-loadable one.

In the modern web, every kilobyte matters. We don’t want to load our app’s whole component library when user enters our site. We need to load components on demand, and after initial load, cache them…
Continue reading “How to Lazy Load features using React and Webpack – codeburst”

React’s Ecosystem as a flexible Framework

  • But in the end, when implementing a larger application, you need a couple of more libraries to have a sophisticated web application with React as its core.
  • The following article will give you an opinionated approach to select from these libraries to build a sophisticated React application.
  • In plain JavaScript, it would be possible to create a React class attribute with conditionals:

    But it is so much easier with the classnames library:

    It works perfectly with CSS modules too.

  • Basically a fetch looks like the following, for instance in a React lifecycle method when a component mounts:

    Basically you wouldn’t have to add any other library to do the job.

  • However, there are common use cases for React’s higher order components that are already solved in a library called recompose.

React’s ecosystem is a flexible framework. The article gives you an opinionated ideal React setup choosing essential libraries…
Continue reading “React’s Ecosystem as a flexible Framework”

Sharing stateful UI logic in React apps using Render Callback components

Sharing stateful UI logic in React apps using Render Callback components



#ReactJS

  • We have three components: an Accordion , Modal , and Thumbnail .
  • We could write each of them as a stateful class component with the same wrapping code, but since they have the same state setup – let’s share it!
  • Let’s abstract the state into a Toggle component (a Render Callback).
  • Now components that use Toggle will have access to their own isOpen and handleToggleClick arguments without having to wire up the state code.
  • The instances of Toggle (Accordion , Modal , and Thumbnail ) can just be stateless function components.

A few examples of abstracting shared logic across multiple components using the Render Callback pattern (aka Function as Child components).
Continue reading “Sharing stateful UI logic in React apps using Render Callback components”

8 things to learn in React before using Redux

  • A component can manage a whole lot of state, pass it down as props to its child components and pass a couple of functions along the way to enable child components to alter the state in the parent component again.
  • Component A is the only component that manages local state but passes it down to its child components as props.
  • In addition, it passes down the necessary functions to enable B and C to alter its own state in A.

    Now, half of the local state of component A is consumed as props by component C but not by component B.

  • When you lift the local state management down to component C, all the necessary props don’t need to traverse down the whole component tree.
  • When a library such as Redux “connects” its state managements layer with React’s view layer, you will often run into a higher order component that takes care of it (connect HOC in react-redux).

Facts about React that should be known before using Redux (or MobX). Most important: Learn React first, then opt-in Redux…
Continue reading “8 things to learn in React before using Redux”

How to Lazy Load features using React and Webpack – codeburst

  • We don’t want to load our app’s whole component library when user enters our site.
  • We need to load components on demand, and after initial load, cache them in the memory for further use.Also we want lazy loading logic to be separated from the component implementations.We can solve this problem using Webpack import functions and Higher order components.Our HOC takes two arguments, second is the component which will be shown while component is loading, because we don’t want our users to be looking at the blank screen.First argument is the getComponent function, this is where we call Webpack import:One might ask why we don’t pass the path directly to the HOC.
  • E.g. if we do something like this: Webpack will bundle all the files in the .
  • If we pass the whole string directly import(‘.
  • But we cannot do this: path = import(path), because Webpack won’t know which files to consider, it won’t have any pattern to match files against.So our HOC, calls import before it mounts and displays the spinner while component is being downloaded.This way we can easily convert any statically imported component into lazy-loadable one.

In the modern web, every kilobyte matters. We don’t want to load our app’s whole component library when user enters our site. We need to load components on demand, and after initial load, cache them…
Continue reading “How to Lazy Load features using React and Webpack – codeburst”

#reactjs component for rendering React components w/ editable source and live preview #JavaScript

  • A component for rendering React Components and ES6 code with editable source and live preview

    In the head of your html document, either add the css files from the demo or from a CDN like:

    In your JSX, require the component and use it like this:

    takes a string of JSX markup as its value.

  • While you can just pass it a string, I find it is easier to make a separate file and use Webpack’s raw loader to load in the raw source.
  • An example file would look like:

    When evaluating the JSX, it needs to be provided a scope object.

  • You can use this option to write higher order components directly in your example code and use your own Render method.
  • NOTE: This option requires that the method be in your code

component-playground – A component for rendering React components with editable source and live preview
Continue reading “#reactjs component for rendering React components w/ editable source and live preview #JavaScript”