The library for web and native user interfaces
(c) react.dev
🐊Putout plugin helps to migrate to new version of React. Not bundled.
npm i putout @putout/plugin-react-hooks -D
Add .putout.json
with:
{
"plugins": ["react"]
}
- ✅ apply-create-root;
- ✅ remove-useless-provider;
- ✅ remove-useless-forward-ref;
- ✅ remove-implicit-ref-return;
Here is list of rules:
{
"rules": {
"react/apply-create-root": "on",
"react/remove-useless-provider": "on",
"react/remove-useless-forward-ref": "on",
"react/remove-implicit-ref-return": "on"
}
}
ReactDOM.render()
was deprecated in March 2022 (v18.0.0). In React 19, we’re removingReactDOM.render()
and you’ll need to migrate to usingReactDOM.createRoot()
:
Check out in 🐊Putout Editor.
import {render} from 'react-dom';
render(<App/>, document.getElementById('root'));
import {createRoot} from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(<App/>);
In React 19, you can render as a provider instead of <Context.Provider>:
Check out in 🐊Putout Editor.
function App() {
const [theme, setTheme] = useState('light');
// ...
return (
<UseTheme.Provider value={theme}>
<Page/>
</UseTheme.Provider>
);
}
function App() {
const [theme, setTheme] = useState('light');
// ...
return (
<UseTheme value={theme}>
<Page/>
</UseTheme>
);
}
Starting in React 19, you can now access ref as a prop for function components: New function components will no longer need
forwardRef
. In future versions we will deprecate and removeforwardRef
.
Check out in 🐊Putout Editor.
const MyInput = forwardRef((props, ref) => {
return (
<input {...props} ref={ref}/>
);
});
const MyInput2 = forwardRef(({value}, ref) => {
return (
<input value={value} ref={ref}/>
);
});
Due to the introduction of ref cleanup functions, returning anything else from a ref callback will now be rejected by TypeScript. The fix is usually to stop using implicit returns.
Check out in 🐊Putout Editor.
const a = (
<div ref={(current) => instance = current}/>
);
function App() {
const [theme, setTheme] = useState('light');
// ...
return (
<UseTheme value={theme}>
<Page/>
</UseTheme>
);
}
MIT