Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix assemblyOptions example for React #5450

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading