Skip to content

Commit

Permalink
docs: fix assemblyOptions example for React (#5450)
Browse files Browse the repository at this point in the history
* docs: fix assemblyOptions example for React

* Update docs/framework-integrations/react.mdx

* Format
  • Loading branch information
Murderlon authored Sep 19, 2024
1 parent 9eb857e commit 59a7aa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions docs/framework-integrations/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,24 @@ params.
```js
// ...
function createUppy(userId) {
return new Uppy({ meta: { userId } }).use(Transloadit, {
async assemblyOptions(file) {
function createUppy() {
const uppy = new Uppy();
uppy.use(Transloadit, {
async assemblyOptions() {
// You can send meta data along for use in your template.
// https://transloadit.com/docs/topics/assembly-instructions/#form-fields-in-instructions
const body = JSON.stringify({ userId: file.meta.userId });
const { meta } = uppy.getState();
const body = JSON.stringify({ userId: meta.userId });
const res = await fetch('/transloadit-params', { method: 'POST', body });
return response.json();
},
});
return uppy;
}

function Component({ userId }) {
// IMPORTANT: passing an initializer function to prevent Uppy from being reinstantiated on every render.
const [uppy] = useState(() => createUppy(userId));
const [uppy] = useState(createUppy);

useEffect(() => {
if (userId) {
Expand Down
2 changes: 1 addition & 1 deletion docs/uploader/transloadit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ signature and return your configuration.

```js
uppy.use(Transloadit, {
async assemblyOptions(file) {
async assemblyOptions() {
const res = await fetch('/transloadit-params');
return res.json();
},
Expand Down

0 comments on commit 59a7aa0

Please sign in to comment.