The React-19 RC has been officially released on April 25, 2024.
In React-19, we can now directly render <Context>
as a Provider
instead of using <Context.Provider>
:
const PostContext = createContext('');
function App({children}) {
return (
<PostContext value="dark">
{children}
</PostContext>
);
}
This is really awesome, we do not have to go through the creation of separate Provider
anymore and this leads to a neat clean code in my opinion.
For example in React-18, we used to do
<PostContext.Provider value="dark">
{children}
</PostContext.Provider>
As per the official React-19 RC docs, the old <Context.Provider> will get deprecated in the near future!