uber / react-view

React View is an interactive playground, documentation and code generator for your components.

Home Page:https://react-view.pages.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean props that default to undefined can’t be explicitly set to false

kapowaz opened this issue · comments

Let’s say I have a component which accepts an optional Boolean prop:

export const MyComponent = ({ shouldDoSomething = undefined }: { shouldDoSomething?: boolean; }) => {
  return (<div>{shouldDoSomething ? 'should do the thing!' : 'should not do the thing'}</div>;
}

If I set up an example for this using react-view, I can’t ever set shouldDoSomething to false, with this configuration:

const propConfig = {
  shouldDoTheThing: {
    type: PropTypes.Boolean,
    description:
      'Should do the thing or not?',
    value: true,
  }
};

If I configure my component example to explicitly set shouldDoTheThing to false, react-view simply omits that prop from the code editor example (and in React Dev Tools you can see the prop is missing; setting it explicitly there works).