Creating a reusable component
See original GitHub issueIs it possible to create a reusable component so that we don’t have to repeat ourselves like this all the time:
const One = Loadable({
loader: () => import('./components/One'),
loading() {
return <Preloader />
}
});
const Two = Loadable({
loader: () => import('./components/Two'),
loading() {
return <Preloader />
}
});
I tried to do it like this:
import Loadable from 'loadable-components';
const Load = ({ loader, ...otherProps }) => {
const LoadableComponent = Loadable(loader, { LoadingComponent: Preloader });
return <LoadableComponent {...otherProps} />;
};
and then:
<Route path="/one" render={props => <Load loader={() => import('components/One')} />} />
<Route path="/two" render={props => <Load loader={() => import('components/Two')} />} />
But I start getting into weird infinite loops with this approach. Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (7 by maintainers)
Top Results From Across the Web
How to Create a Truly Reusable React Component from Scratch
How to Create a Reusable React Component ... Now, create an InputControl.js file inside the components folder with the following code: ... current...
Read more >A Practical Guide to Creating Reusable React Components
Top Three Indicators of a Reusable React Component · Repetitive creation of wrappers with the same CSS style · Repetitive use of event...
Read more >How to Create a Reusable React Form component - Section.io
A Reusable component is a piece of User Interface that can be used in many parts of an application to build and render...
Read more >Reusable Components in React — A Practical Guide
So, to create a re-usable component in React, all you need to do is create a function that has a capital letter as...
Read more >How to make your React components more reusable
How to make your React components more reusable · Use container component pattern · Generic versus specialized components · Be mindful about what ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
react-loadable
library given demonstrated on HOC component to avoid repetitions inside FAQ’shttps://github.com/jamiebuilds/react-loadable#how-do-i-avoid-repetition