Closed extempl closed 6 months ago
React doesn't know, at the time that App is rendered, whether RenderWrapper is going to render its children or not, so it has to always, unconditionally, evaluate its propTypes. The current behavior is correct - if the prop is required, it needs to always be provided. A better approach would be an inline jsx ternary instead of a wrapper that does the conditional rendering far away from where the element is created.
Either way, this is a question for React itself, and not the prop-types repo.
With conditional wrapper like this:
It spams with
prop data is marked as required, but its value is null
warnings, while in fact, even that the component returned from render method, its render never called.If you wandering why would anyone use it like so - we use for loading state wrapper, where required prop is provided later and when it is - nested component is rendered.
Live Demo: https://codesandbox.io/p/sandbox/prop-types-49c3tn