question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get value in `setValue`

See original GitHub issue

I’m trying to make a conditional in my setValue like this:

setValue={
   value !== 'custom' ? props.setValue(value) : props.setIsOverlayVisible(true)
}

However, the setValue callback returns a function instead of the value and I can’t do it in onChangeValue because I need it to retain the previous value if “custom” is selected. How do I go about getting the value in setValue ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hossein-zarecommented, Mar 7, 2022

You shoudn’t touch the setValue prop.

setValue={props.setValue}

to retain values:

const currentValueRef = useRef(null);

<DropDownPicker
  setValue={props.setValue}
  onChangeValue={(value) => {
    if (value === 'custom') {
      props.setIsOverlayVisible(true);
      setValue(currentValueRef.current);
    } else {
      currentValueRef.current = value;
    }
  }}
  ...
/>
0reactions
KrisLaucommented, Mar 18, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >
Solved: GetValue and setValue - ServiceNow Community
Variable in catalog item has some value, onChange of the field value, i should get the value and then append % to same...
Read more >
PropertyInfo.SetValue Method (System.Reflection)
The SetValue(Object, Object) overload sets the value of a non-indexed property. To determine whether a property is indexed, call the GetIndexParameters method.
Read more >
How to setValue and getValue when using useFormContext in ...
If you wnat to get the input value outside the Controller then the getValue must be the one returned by useForm.
Read more >
Why values set by setValue are not get on getValues ... - GitHub
I have set the values of a field using methods.setValue('name', value, {shouldValidate: true, shouldDirty: true }) and get them using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found