score:2
I don't know why you think using default exports should be avoided :) I think it's just a convention that some teams have. So adding export default LazyArea;
is a valid way to deal with this. You won't have too many lazy modules anyway.
That's why the solution from React docs could also work where you just put that default export into its own file.
The other recommended approach is to change import code to convert it to default inline:
const LazyArea = React.lazy(() =>
import("./lazy-area").then((module) => ({
default: module.LazyArea,
}))
);
But that's seems like too much work for me :) So I created react-lazily which does what you would expect.
Example
const { LazyArea } = lazily(() => import('./lazy-area'));
it's just a small wrapper around React.lazy
, but it allows you to have a really straight forward code, like that:
import { lazily } from 'react-lazily';
const { Component1, Component2 } = lazily(() => import('./Components'))
Source: stackoverflow.com
Related Query
- React lazy with TypeScript and Redux
- Typing redux forms v7 with TypeScript and React
- Connecting a component with OwnProps using react redux and typescript in the .NET Core 2.0 reactredux template project
- React observable epic with Redux Toolkit and Typescript
- Programmatic React Router navigation with TypeScript and Redux in class component
- React - useRef with TypeScript and functional component
- Typescript and React setting initial state with empty typed array
- Cannot read property '.then' of undefined when testing async action creators with redux and react
- Dealing with local state in react and redux
- Fractal Project Structure with React and Redux - pros/cons
- Calling an action from a different reducer with React and redux
- React hook useRef not working with styled-components and typescript
- React event handlers with Typescript and JSX
- How to use React with Typescript and SASS
- Performance issues with a tree structure and shouldComponentUpdate in React / Redux
- Paginate date-specific results from an API with React and Redux
- How to test snapshots with Jest and new React lazy 16.6 API
- Typescript and React with File Upload (typing)
- React and typescript with webpack typing issue
- Multiple Registration Form with redux and react
- Async Image Load with React and Redux
- onEnter Transitions with React Router and Redux Simple Router Dont Render New Route's Component
- How to use HOC with redux compose and Typescript
- Create React App with TypeScript and NPM Link: Enums causing Module parse failed
- Form in React and TypeScript with DRY handle of change
- Sync queryParameters with Redux state and react router for function components
- How to test React Router params with Redux and enzyme
- How to add login authentication and session to ReactJS React Router and Redux with MongoDB + NodeJS Express?
- React redux connect with with styles and withrouter
- Creating reusable Button Component with React and Typescript with not assignable type error
More Query from same tag
- getting undefined is not a function when trying to .map an api in react
- How to Stop component to refresh after axios post in react. After uploading image from formData
- How to use material-ui breakpoint rule in external styles?
- can't use makeStyles
- How to call a function in react js from an external JS File
- Moving first item in array to the last position
- Show/Hide ReactJS components without losing their internal state?
- Access ref of component in another component?
- Component not returning UI even though props are being delivered
- What is the reverse assignment (destructuring assignment) in ES6 javascript?
- Add cookie to axios interceptor request handler
- How to conditionally set properties on XY bar chart in amCharts v4?
- How to avoid Material UI Select focus when option is chosen?
- Function overloading with typescript on a react component?
- Passing several arguments into react component
- How can I exclude the past (past days) using moment js?
- Change Route after a function is done in ReactJs
- Populate Dropdown Select with Props React
- infinite post loop when calling action
- Generate a json list by parsing a list
- Getting props as undefined in component returned from getStaticProps
- Value type error message displaying instead of required error message on empty input submission
- How to change closeMenuOnSelect value on event in react-select?
- How to conditionally show element in react JSX?
- My material UI custom classes are being overridden by material UI's default classes
- Load confirmation URL in Embedded app itself in Shopify
- should NOT have additional property 'nodeModulesPath'(Expo React Native)
- React router v6 how to get current route in class component
- How retrieve text from draftjs
- Change all values of nested state?