Skip to content

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

@kapowaz

Description

@kapowaz

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions