Skip to content

Commit

Permalink
perf[react-native]: Memoized Blocks Component to free up UI thread. (#…
Browse files Browse the repository at this point in the history
…3814)

## Description

`Suspense`:
Added `React.Suspense` to defer the rendering of the `Content` component
until it is fully loaded.

`Memoization`:
`React.memo` to memoize computationally expensive operations within the
`Blocks` component. To prevents unnecessary recalculations of processed
blocks during re-renders, reducing the load on the UI thread.

_Screenshot_
Before:
<img width="798" alt="Screenshot 2025-01-13 at 12 20 38 PM"
src="https://github.com/user-attachments/assets/91ddb89c-2ddd-4930-b62f-7497783ad948"
/>

After:
<img width="798" alt="Screenshot 2025-01-13 at 12 37 41 PM"
src="https://github.com/user-attachments/assets/6dd776b0-3d82-46f1-a98a-7d28e553d44c"
/>

---------

Co-authored-by: Yash Wadhia <[email protected]>
  • Loading branch information
yash-builder and Yash Wadhia authored Jan 24, 2025
1 parent eb3d1af commit 12b35b2
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .changeset/early-pillows-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@builder.io/sdk-react-native": patch
---

- Enchanced performance: Implemented memoization for the Blocks components
- Flatlist usage: Configured Flatlist for smoother rendering of block components
These changes aims to improve UI responsiveness and reduce rendering overhead
2 changes: 2 additions & 0 deletions .changeset/nice-llamas-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
99 changes: 65 additions & 34 deletions examples/nextjs-app-dir-v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nextjs-app-dir-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@builder.io/sdk-react": "^1.0.23",
"@builder.io/sdk-react": "^3.0.1",
"next": "14.1.1",
"react": "^18",
"react-dom": "^18"
Expand Down
15 changes: 15 additions & 0 deletions examples/nextjs-app-dir-v2/src/app/components/MyFunComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client';
import { useState } from 'react';

export const MyFunComponent = (props: { text: string }) => {
const [count, setCount] = useState(0);
return (
<div>
<h3>{props.text.toUpperCase()}</h3>
<p>{count}</p>
<button onClick={() => setCount(prev => prev + 1) }>Click me</button>
</div>
);
};

export default MyFunComponent;
18 changes: 18 additions & 0 deletions examples/nextjs-app-dir-v2/src/app/components/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

'use client';
import dynamic from 'next/dynamic';
import { type RegisteredComponent } from "@builder.io/sdk-react";

export const customComponents: RegisteredComponent[] = [
{
component: dynamic(() => import('./MyFunComponent')),
name: 'MyFunComponent',
inputs: [
{
name: 'text',
type: 'string',
defaultValue: 'Hello world',
},
],
},
];
Loading

0 comments on commit 12b35b2

Please sign in to comment.