This PR addresses the upcoming deprecation of defaultProps in function components as signaled by React's warning: "Warning: ScreenClassProvider: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead." The changes involve updating the ScreenClassProvider, Col, Container, Row, Hidden, and Visible components within the react-grid-system library to use default function parameters for props instead of relying on defaultProps. This update ensures forward compatibility with future versions of React and adheres to modern JavaScript best practices.
Changes
ScreenClassProvider: Default parameters are set directly in the function signature for useOwnWidth, children, and fallbackScreenClass.
Col: Introduced default function parameters for all props, ensuring any undefined props fall back to their intended defaults.
Container: Updated to use default parameters, particularly for the fluid and style props, aligning with React's functional component recommendations.
Row: Adjusted to define default values for style, align, justify, wrap, debug, nogutter, gutterWidth, component, and direction directly in the function signature.
Hidden and Visible: Both components now use default parameters to manage visibility across various screen classes.
Rationale
React is moving away from defaultProps in function components in favor of default function parameters, a more standard JavaScript approach. This change aligns react-grid-system with the latest React best practices and prepares it for future React versions. Furthermore, it simplifies the component code by leveraging default function parameters, which are more concise and easier to read.
Testing
The modifications were tested to ensure they don't alter the existing behavior of the react-grid-system. Components continue to function correctly with default props as expected, and the console warning about defaultProps deprecation is resolved.
I look forward to any feedback or suggestions for further improvement.
Overview
This PR addresses the upcoming deprecation of
defaultProps
in function components as signaled by React's warning: "Warning: ScreenClassProvider: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead." The changes involve updating theScreenClassProvider
,Col
,Container
,Row
,Hidden
, andVisible
components within thereact-grid-system
library to use default function parameters for props instead of relying ondefaultProps
. This update ensures forward compatibility with future versions of React and adheres to modern JavaScript best practices.Changes
useOwnWidth
,children
, andfallbackScreenClass
.fluid
andstyle
props, aligning with React's functional component recommendations.style
,align
,justify
,wrap
,debug
,nogutter
,gutterWidth
,component
, anddirection
directly in the function signature.Rationale
React is moving away from
defaultProps
in function components in favor of default function parameters, a more standard JavaScript approach. This change alignsreact-grid-system
with the latest React best practices and prepares it for future React versions. Furthermore, it simplifies the component code by leveraging default function parameters, which are more concise and easier to read.Testing
The modifications were tested to ensure they don't alter the existing behavior of the
react-grid-system
. Components continue to function correctly with default props as expected, and the console warning aboutdefaultProps
deprecation is resolved.I look forward to any feedback or suggestions for further improvement.