Refactor: Replace defaultProps with Default Function Parameters #506
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.