Open djkgamc opened 1 year ago
Hety @djkgamc,
an outdated version 1.2.0 is being used In your codesandbox, whereas the current version is 2.4.5.
That is the problem!
In that case, the fix to the README would be to update the package in your linked Sandbox, as the Sandbox link above is the link from your README, labeled "Example" over here. https://github.com/uploadcare/react-widget#ref-widgetapiref
Describe the bug
README is incorrect or there is a bug in the code for WidgetRef
See this section in the readme here - https://github.com/uploadcare/react-widget
ref: widgetApiRef Define a reference object to address the Widget API wrapper. Use it to access these methods: value, openDialog, reloadInfo and getInput.
value() is the alias for widget.value() openDialog() is the alias for widget.openDialog() reloadIngo() is the alias for widget.reloadInfo() getInput() returns widget's input element instance.
Now try this code:
import React, { useRef } from "react"; import ReactDom from "react-dom"; import { Widget } from "@uploadcare/react-widget";
import "./styles.css";
const Example = () => { const widgetApi = useRef();
return (
); }; ReactDom.render( , document.querySelector("#app"));
You'll get the error: widget.value is not a function
Expected behavior
widget.value should be a function...
Code / screenshots
Environment
I ran this code by modifying the example here https://codesandbox.io/s/keu2y