Using Recompose’s Branch to Conditionally Render Components
First, let’s take a look at the definition for
test: (props: Object) => boolean,
It takes 3 arguments
testa function that receives
propsas its only argument and must return a
lefta higher order component that will be applied if
righta higher order component that will be applied if
It will return `HigherOrderComponent` which means we will still need to call it as a function with our
BaseComponent as the only argument.
Here we use branch to conditionally apply
wrapRed to the
right arguments are expected to be higher order functions so we have to provide a function not a React component.
Conditionally rendering based on auth.
Home.js shows an example with code splitting
RedirectExample.js shows an example of using React Router’s
Redirect component to redirect when unauthorized.