Skip to content

Commit

Permalink
fix(loading): Update when to set loading state (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
brdlyptrs authored May 23, 2023
1 parent 7c03d8d commit 0e2c114
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Run [demo application](./demo/app) in development mode to test [react-bndl libra

#### Scripts
- `start`: Starts development server and builds demo application in development mode
- `start`: Starts development server only
- `build:lib`: Create production distribution that exports a CommonJS and ESM version of the react-bndl library
- `build:app`: Create a production bundle of the demo application
- `fix:lint`: Attempt to fix any lint errors
Expand Down
2 changes: 1 addition & 1 deletion demo/app/main/src/examples/ExampleHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ExampleHook = () => {
<>
{(isLoading && !data) ?
<div>Loading</div> :
(!isLoading && error) ?
(error || (!isLoading && !data)) ?
<div>{error.message}</div> :
<DynamicComponent component={data}>
Dynamic Component
Expand Down
2 changes: 1 addition & 1 deletion lib/src/component/BundleComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function BundleComponent({ path, name, component, children, LoaderCompone

if (isLoading && !data)
return renderLoader();
if (error || !data && !isLoading)
if (error || (!data && !isLoading))
return renderError(error);
else
return (
Expand Down
3 changes: 2 additions & 1 deletion lib/src/hook/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ interface IStatus {
export const bundles = new Map<string, IBundle>();

export function useBundle({ path, name, component }:IProps) {
const [status, setStatus] = React.useState<IStatus>({ isLoading: false, error: null, data: null });
const bundleExists = bundles.get(name);
const [status, setStatus] = React.useState<IStatus>({ isLoading: !bundleExists, error: null, data: null });

const scope = getScope();

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bndl",
"version": "1.0.1",
"version": "1.0.2",
"description": "A library that allows users to split their React application into multiple bundles and load them each dynamically.",
"keywords": [
"React",
Expand Down Expand Up @@ -32,6 +32,7 @@
},
"scripts": {
"start": "pnpm --filter @bndl/demo run start",
"start:server": "pnpm --filter @bndl/demo run start:server",
"build:lib": "pnpm --filter @bndl/lib run build",
"build:app": "pnpm --filter @bndl/demo run build:prod",
"fix:lint": "pnpm --filter @bndl/* run fix:lint",
Expand Down

0 comments on commit 0e2c114

Please sign in to comment.