@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 CHANGED
@@ -1,8 +1,8 @@
1
- # Builder.io React NextJS SDK (BETA)
1
+ # Builder.io React SDK v2 (BETA)
2
2
 
3
- This is the Builder NextJS SDK, `@builder.io/sdk-react-nextjs`. It is intended to be used _only_ with NextJS's app directory, and has hard dependencies on NextJS-specific functionality that only works in the app directory.
3
+ This is the React v2 SDK, `@builder.io/sdk-react`.
4
4
 
5
- If you are using NextJS's pages directory, use the [React gen2 SDK](../react/) in Beta, or the stable React gen1 SDK [here](../../../react/) (i.e. `builder.io/react`).
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. This needs to be created created with the name `app/[[...slug]]/page.tsx`, so it catches all routes:
32
+ Here is a simplified example showing how you would use both:
31
33
 
32
34
  ```tsx
33
- import {
34
- RenderContent,
35
- getBuilderSearchParams,
36
- getContent,
37
- } from '@builder.io/sdk-react-nextjs';
38
-
39
- interface MyPageProps {
40
- params: {
41
- slug: string[];
42
- };
43
- searchParams: Record<string, string>;
44
- }
45
-
46
- const apiKey = 'YOUR_API_KEY_HERE';
47
-
48
- export default async function Page(props: MyPageProps) {
49
- const urlPath = '/' + (props.params?.slug?.join('/') || '');
50
-
51
- const content = await getContent({
52
- model: 'page',
53
- apiKey,
54
- options: getBuilderSearchParams(props.searchParams),
55
- userAttributes: { urlPath },
56
- });
57
-
58
- return <RenderContent content={content} model="page" apiKey={apiKey} />;
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-nextjs
82
+ npm install @builder.io/sdk-react
76
83
  ```
77
84
 
78
85
  ## Examples
79
86
 
80
- - [Next.js SDK](../../../../examples/next-js-sdk-gen-2-experimental-app-directory)
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.5";
1
+ export declare const SDK_VERSION = "0.4.6-0";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.4.5";
1
+ export const SDK_VERSION = "0.4.6-0";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-nextjs",
3
3
  "description": "Builder.io SDK for React",
4
- "version": "0.4.5",
4
+ "version": "0.4.6-0",
5
5
  "files": [
6
6
  "dist"
7
7
  ],