For a custom component the useStateNumber function does not allow negative initialValues

In a custom component using the useStateNumber function does not allow for setting negative numbers as the initialValue:

e.g.

  const [bounds_sw_lng, _setBoundsSWLng] = Retool.useStateNumber({
    name: 'bounds_sw_lng',
    initialValue: -119.123
  });

errors out with this error message:

Generating & updating manifest...

✘ [ERROR] Retool.useStateNumber was called with a non literal parameter "-119.754906". "-119.754906" is not allowed as a parameter to Retool.useStateNumber because it's a PrefixUnaryExpression, only literal values such as "example-string" or [1,2,3] are allowed. [plugin generate-manifest]

But non negative numbers are allowed e.g.

  const [bounds_sw_lng, _setBoundsSWLng] = Retool.useStateNumber({
    name: 'bounds_sw_lng',
    initialValue: 0
  });

Is this a bug? Or am I doing something incorrect?

2 Likes

Hi @cchan! Welcome to the community. :wave:

It certainly sounds like you found a bug, but it might have been squashed in the most recent update to the @tryretool/custom-component-support library. I updated a few days ago and am unable to replicate this behavior.

Can you try updating to see if this issue persists? Let me know what you find!

Thanks @Darren, yes I reported the bug to Daniel and looks like he was able to fix it. It's working for me now with the update :tada:.

1 Like