Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace defaultProps with Default Function Parameters #506

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

mateeusduarte
Copy link
Contributor

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 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.

@gerbenmeyer
Copy link
Contributor

Awesome stuff!

@gerbenmeyer gerbenmeyer merged commit 008655e into sealninja:master Feb 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants