瀏覽代碼

docs: fix assemblyOptions example for React (#5450)

* docs: fix assemblyOptions example for React

* Update docs/framework-integrations/react.mdx

* Format
Merlijn Vos 7 月之前
父節點
當前提交
59a7aa0271
共有 2 個文件被更改,包括 9 次插入6 次删除
  1. 8 5
      docs/framework-integrations/react.mdx
  2. 1 1
      docs/uploader/transloadit.mdx

+ 8 - 5
docs/framework-integrations/react.mdx

@@ -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) {

+ 1 - 1
docs/uploader/transloadit.mdx

@@ -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();
 	},