ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
187 stars 29 forks source link

chore: change ThemeProvider's children to non-required #58

Closed wjq990112 closed 1 year ago

wjq990112 commented 1 year ago

In React, as a Provider, the children prop is always optional. Therefore, modify the children prop in ThemeProviderProps to be non-required.

arvinxx commented 1 year ago

is there any usage to use ThemeProvider without children?

I thought there is no such usage so I make children props required.

wjq990112 commented 1 year ago

I understand your point of view that setting children as required ensures that the ThemeProvider always wraps a child component. However, in React, the children prop of a Provider is usually optional for the following reasons:

  1. Consistency: Other Provider components in React (such as the Provider in React-Redux) typically have children as optional. Following this convention makes it easier for developers to understand and use the ThemeProvider.

  2. Flexibility: Although in most cases we indeed want the ThemeProvider to wrap child components, there might be scenarios where one needs to dynamically add or remove child components at runtime. In such cases, having children as optional provides greater flexibility.

  3. Usability: Making children a non-required prop simplifies certain testing and experimentation scenarios. For example, during development, a developer might want to temporarily use the ThemeProvider without passing any child components. If children were required, this would result in unnecessary errors and extra work.

In conclusion, I suggest making the children prop of the ThemeProvider non-required. This will make the component more flexible, usable, and consistent with other React Provider components.

arvinxx commented 1 year ago

Get it, thanks for your contrubution~

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 3.2.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: