Skip to content

widgetApiRef.value is not a function  #382

@djkgamc

Description

@djkgamc

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 (


<button
onClick={() => {
const widget = widgetApi.current
widget.value("https://i0.wp.com/www.techjunkie.com/wp-content/uploads/2020/08/How-to-Copy-and-Get-a-Link-to-Any-Online-Image-Embedded-in-a-Website.jpg?resize=660%2C430&ssl=1")
const dialog = widget.openDialog();

      console.log(dialog);
      dialog.switchTab("url");
    }}
  >
    Click me
  </button>

  <Widget ref={widgetApi} publicKey="demopublickey" preloader={null} />
</div>

);
};
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions