@builder.io/react 1.1.48-0 → 1.1.49-1

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
@@ -45,26 +45,26 @@ All data passed down is available in Builder [actions and bindings](https://www.
45
45
  model="page"
46
46
  data={{
47
47
  products: productsList,
48
- myFunction: () => alert('Triggered!'),
49
48
  foo: 'bar'
50
49
  }} >
51
50
  ```
52
51
 
53
- You can also pass down complex data like custom objects and libraries you can use `context`. Similar to React context, context passes all the way down (e.g. through symbols, etc). This data is not observed for changes and mutations
52
+ You can also pass down functions, complex data like custom objects and libraries you can use `context`. Similar to React context, context passes all the way down (e.g. through symbols, etc). This data is not observed for changes and mutations
54
53
 
55
54
  ```tsx
56
55
  <BuilderComponent
57
56
  model="page"
58
57
  context={{
58
+ addToCart: () => myService.addToCart(currentProduct),
59
59
  lodash: lodash,
60
60
  }} >
61
61
  ```
62
62
 
63
- Context is available in [actions and bindings](https://www.builder.io/c/docs/guides/custom-code) as `context.*`, such as `context.lodash` in the example above
63
+ Context is available in [actions and bindings](https://www.builder.io/c/docs/guides/custom-code) as `context.*`, such as `context.lodash` or `context.myFunction()` in the example above
64
64
 
65
65
  #### Passing complex
66
66
 
67
- Everything passed down is available on the `state` object in data and actions - e.g. `state.products[0].name` or `state.myFunction()`
67
+ Everything passed down is available on the `state` object in data and actions - e.g. `state.products[0].name`
68
68
 
69
69
  See more about using data passed down [here](https://www.builder.io/c/docs/react/custom-actions)
70
70
 
@@ -133,6 +133,75 @@ Builder.registerComponent(CodeBlockComponent, {
133
133
 
134
134
  See our full guide on [registering custom components here](https://www.builder.io/c/docs/custom-react-components)
135
135
 
136
+ ### BuilderContent
137
+
138
+ #### Usage with Data Models
139
+
140
+ Although you can already fetch data models from our Content API directly and use it as you would any other API resource, with a BuilderContent component you are able to use live Editing / Previewing / [A/B testing](https://forum.builder.io/t/a-b-testing-data-models/158) of your Data Models within the Builder Visual Editor.
141
+
142
+ ##### Example, setting up an editable theme:
143
+ ```tsx
144
+ <BuilderContent model="site-settings"> { (data, loading) => {
145
+ If (loading) {
146
+ return <Spinner />
147
+ }
148
+ return <>
149
+ /*pass values down to an example ThemeProvider, used as a wrapper in your application*/
150
+ <ThemeProvider theme={data.theme} >
151
+ {props.children}
152
+ </ThemeProvider>
153
+ </>
154
+ }}
155
+ </BuilderContent>
156
+ ```
157
+
158
+
159
+ #### Usage with Page/Section Custom Fields
160
+
161
+ Page and section models in builder can be extended with [custom fields](https://www.builder.io/c/docs/custom-fields). To enable live editing / previewing on components that uses those custom fields, you can use BuilderContent to pass input data from the model to your components that are outside the rendered content
162
+
163
+ ##### Example, passing Custom Field input:
164
+ ```tsx
165
+ <BuilderContent model="landing-page">{ (data) => {
166
+ /*use your data here within your custom component*/
167
+ return <>
168
+ <FeaturedImage image={data.featuredImage} />
169
+ <BuilderComponent content={content} model="landing-page" />
170
+ </>
171
+ }}
172
+ </BuilderContent>
173
+ ```
174
+
175
+ #### Passing content manually
176
+
177
+ This is useful for doing server side rendering, e.g. with [Gatsby](https://github.com/BuilderIO/builder/tree/master/examples/gatsby) and [Next.js](https://github.com/BuilderIO/builder/tree/master/examples/next-js) or via
178
+ loading data from other sources than our default APIs, such as data in your own database saved via [webhooks](https://www.builder.io/c/docs/webhooks)
179
+
180
+ ```tsx
181
+ const content = await builder.get(‘your-data-model’, { ...options });
182
+ if (content) {
183
+ /*use your data here*/
184
+ return <BuilderContent model="your-data-model" content={content} >
185
+ }
186
+ ```
187
+
188
+ #### Advanced querying
189
+ When using custom [models](https://www.builder.io/c/docs/guides/getting-started-with-models) and [fields](https://www.builder.io/c/docs/custom-fields) you can do more advanced filtering of your content with [queries](<(https://www.builder.io/c/docs/custom-fields)>)
190
+ and [targeting](https://www.builder.io/c/docs/guides/targeting-and-scheduling)
191
+
192
+ ```tsx
193
+ import { BuilderContent, builder } from '@builder.io/react';
194
+
195
+ builder.setUserAttributes({ isLoggedIn: false })
196
+
197
+ export default () => <div>
198
+ <BuilderContent
199
+ model="your-data-model"
200
+ options={{ query: { 'data.something.$in': ['value a', 'value b'] } }} />
201
+ <!-- some other content -->
202
+ </div>
203
+ ```
204
+
136
205
  ### builder
137
206
 
138
207
  The React SDK exports the core SDK's [builder object](../core), which can be used for setting things like
@@ -1,4 +1,4 @@
1
- "use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var sdk=require("@builder.io/sdk"),core=require("@emotion/core"),React=require("react"),React__default=_interopDefault(React),ReactDOM=_interopDefault(require("react-dom")),hash=_interopDefault(require("hash-sum")),version="1.1.47",_a;"undefined"!=typeof window&&(null===(_a=window.parent)||void 0===_a||_a.postMessage({type:"builder.isReactSdk",data:{value:!0,supportsPatchUpdates:"v3",priorVersion:version}},"*"))
1
+ "use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var sdk=require("@builder.io/sdk"),core=require("@emotion/core"),React=require("react"),React__default=_interopDefault(React),ReactDOM=_interopDefault(require("react-dom")),hash=_interopDefault(require("hash-sum")),version="1.1.49-0",_a;"undefined"!=typeof window&&(null===(_a=window.parent)||void 0===_a||_a.postMessage({type:"builder.isReactSdk",data:{value:!0,supportsPatchUpdates:"v3",priorVersion:version}},"*"))
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use