Facebook has released React 15.5 to give developers adequate time to adjust to a big change in 16.
In a blog post, Andrew Clark laid out the news that two features, React.PropTypes
and React.createClass
are being deprecated from the main package. To prepare for version 16, they have been moved into their own packages as a way to improve the code size going forward.
For now, developers will see a warning in the console if they use either of these features from the main package. If a developer doesn't fix it now, their code will break in version 16.
When React was initially released, there was no idiomatic way to create classes in JavaScript, so we provided our own:
React.createClass
.Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. Along with functional components, JavaScript classes are now the preferred way to create components in React.
If recoding an app to use JavaScript classes is not an option, developers can also choose to switch to the create-react-class module available on NPM. This will still require changes to the code, but avoids using JavaScript classes.
The removal of propTypes
shouldn't be too big of a loss for most developers. Those that code React in TypeScript or that incorporate Flow into their tool chain have had better ways of type checking React projects. For example, a TypeScript developer might define their props
with a strong type:
interface MyProps { firstName: string, lastName: string }
export default class MyComponent extends React.Component<MyProps, any> {
}
Declaring a class in this way would automatically give a TypeScript developer proper type checking. The use of propTypes
would already be redundant.
Version 15.5 is also the last release of the React addons. While some of them have been pushed to other packages, createFragment
has been incorporated into version 16 which has support for fragments built-in.