Closed wjq990112 closed 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.
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:
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
.
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.
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.
Get it, thanks for your contrubution~
:tada: This PR is included in version 3.2.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
In React, as a Provider, the
children
prop is always optional. Therefore, modify thechildren
prop inThemeProviderProps
to be non-required.