Semantic-ui-react: Creating a Checkbox or Modal emits an error in the console when using Preact

Created on 17 Jul 2017  路  5Comments  路  Source: Semantic-Org/Semantic-UI-React

Steps

  1. Using the preact-cli, build a basic project.
  2. npm install --save semantic-ui-react
  3. Add a simple form with a checkbox element anywhere in the project.
    Sample code:
<Form>
    <Form.Checkbox label='Why the errors?'/>
</Form>
  1. The following errors show up in the console log.

    1. Checkbox is missing "defaultChecked" propTypes validation for auto controlled prop "checked".

    2. Checkbox is missing propTypes validation for auto controlled prop "checked".

    3. Checkbox is missing "defaultIndeterminate" propTypes validation for auto controlled prop "indeterminate".

    4. Checkbox is missing propTypes validation for auto controlled prop "indeterminate".

Expected Result

No errors are emitted.

Actual Result

4 errors are emitted.

Version

0.71.1

Testcase

Repository is pretty barebones, but had to make a separate project in order to demonstrate the issue.
https://github.com/rbscott/auto-controlled-error

Notes

I am not sure if Preact is official supported, but it seems to mostly work. If someone points me in the right direction, I could put together a Pull Request.

help wanted

Most helpful comment

@levithomason thanks for the info. It looks like preact removes prop types for all builds. There is a PR to change this behavior so it only removes propTypes during production builds. I believe this will resolve this issue.

All 5 comments

@rbscott Thanks for report. However, you're right, PReact isn't officially supported. Help there is much appreciated. Warnings are come from AutoControlledComponent, but issue is quite strange.

PRs increasing interop with other libraries are very much welcomed. Closing for housekeeping as there are no errors with React and this library is intended to be used with React only.

In case it is of help, these are errors for developers that are only logged when NODE_ENV !== 'production'. We check that the Component.constructor.propTypes include the necessary keys for the component. Preact must be doing something to the propTypes so that some are missing. Namely, the default* propType for checked and indeterminate.

@levithomason thanks for the info. It looks like preact removes prop types for all builds. There is a PR to change this behavior so it only removes propTypes during production builds. I believe this will resolve this issue.

@rbscott preact-compat is the solution you are looking for.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

the-simian picture the-simian  路  24Comments

levithomason picture levithomason  路  24Comments

ryardley picture ryardley  路  27Comments

mmahalwy picture mmahalwy  路  45Comments

levithomason picture levithomason  路  39Comments