uber / react-view

React View is an interactive playground, documentation and code generator for your components.
https://react-view.pages.dev
MIT License
697 stars 41 forks source link

Do not ignore zero value in generated code #53

Closed anelook closed 3 years ago

anelook commented 3 years ago

We should not ignore zero value when generating code for a property of type Number.

Can be reproduce in https://codesandbox.io/s/i3dbn?fontsize=14&hidenavigation=1&theme=dark by adding


      importantProperty: {
        type:PropTypes.Number,
        value: 0,
        defaultValue: undefined,
        description: 'Do not ignore me!'
      }

When changing value from '0' to '1', the code generator works as expected. However, when value is set to '0', code generator ignores 'importantProperty'.

Underlying issue: At the moment it is treated as boolean and code-generator return Null for

getAstPropsArray(
        {
          a: {
            value: 0,
            defaultValue: undefined,
            type: PropTypes.Number,
            description: '',
          },
        },
        {}
      )[0]
anelook commented 3 years ago

Hi Vojtech, are there any concerns for this change? I see that only code review is pending :)

tajo commented 3 years ago

lgtm, thanks!