@builder.io/sdk-react-nextjs 0.4.5 → 0.4.6-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -32
- package/dist/constants/sdk-version.d.ts +1 -1
- package/dist/constants/sdk-version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Builder.io React
|
|
1
|
+
# Builder.io React SDK v2 (BETA)
|
|
2
2
|
|
|
3
|
-
This is the
|
|
3
|
+
This is the React v2 SDK, `@builder.io/sdk-react`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
NOTE: it is still in Beta. For the stable React v1 SDK [go here](../../../react/), i.e. `builder.io/react`.
|
|
6
6
|
|
|
7
7
|
## API Reference
|
|
8
8
|
|
|
@@ -10,6 +10,8 @@ To use the SDK, you need to:
|
|
|
10
10
|
|
|
11
11
|
- fetch the builder data using `getContent`: you can see how to use it here https://www.builder.io/c/docs/content-api, and how it differs from the React V1 SDK's `builder.get()` function.
|
|
12
12
|
|
|
13
|
+
NOTE: if you are using the SDK in next v13's app directory, you will have to import `getContent` from @builder.io/sdk-react/server`. this is a special import that guarantees you don't import any client components with your data fetching.
|
|
14
|
+
|
|
13
15
|
- pass that data to the `RenderContent` component, along with the following properties:
|
|
14
16
|
|
|
15
17
|
```ts
|
|
@@ -27,35 +29,40 @@ type RenderContentProps = {
|
|
|
27
29
|
};
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
Here is a simplified example showing how you would use both
|
|
32
|
+
Here is a simplified example showing how you would use both:
|
|
31
33
|
|
|
32
34
|
```tsx
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
import { RenderContent, getContent, isPreviewing } from '@builder.io/sdk-react';
|
|
36
|
+
import { useEffect, useState } from 'react';
|
|
37
|
+
|
|
38
|
+
const BUILDER_PUBLIC_API_KEY = 'YOUR API KEY';
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
const [content, setContent] = useState(undefined);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
getContent({
|
|
45
|
+
model: 'page',
|
|
46
|
+
apiKey: BUILDER_PUBLIC_API_KEY,
|
|
47
|
+
userAttributes: {
|
|
48
|
+
urlPath: window.location.pathname || '/',
|
|
49
|
+
},
|
|
50
|
+
}).then((content) => {
|
|
51
|
+
setContent(content);
|
|
52
|
+
});
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const shouldRenderBuilderContent = content || isPreviewing();
|
|
56
|
+
|
|
57
|
+
return shouldRenderBuilderContent ? (
|
|
58
|
+
<RenderContent
|
|
59
|
+
content={content}
|
|
60
|
+
model="page"
|
|
61
|
+
apiKey={BUILDER_PUBLIC_API_KEY}
|
|
62
|
+
/>
|
|
63
|
+
) : (
|
|
64
|
+
<div>Content Not Found</div>
|
|
65
|
+
);
|
|
59
66
|
}
|
|
60
67
|
```
|
|
61
68
|
|
|
@@ -72,9 +79,14 @@ To check the status of the SDK, look at [these tables](../../README.md#feature-i
|
|
|
72
79
|
## Getting Started
|
|
73
80
|
|
|
74
81
|
```
|
|
75
|
-
npm install @builder.io/sdk-react
|
|
82
|
+
npm install @builder.io/sdk-react
|
|
76
83
|
```
|
|
77
84
|
|
|
78
85
|
## Examples
|
|
79
86
|
|
|
80
|
-
- [
|
|
87
|
+
- [React](../../../../examples/react-v2/)
|
|
88
|
+
- [Next.js + app dir](../../../../examples/next-app-directory)
|
|
89
|
+
|
|
90
|
+
## Fetch
|
|
91
|
+
|
|
92
|
+
This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.4.
|
|
1
|
+
export declare const SDK_VERSION = "0.4.6-0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.4.
|
|
1
|
+
export const SDK_VERSION = "0.4.6-0";
|