Sept. 26, 2023, 6:29 a.m. | BlackMan

DEV Community dev.to

The useContext() hook in React allows function components to access the context value for a context object. It takes the context object as the only argument and returns the current context value as given by the nearest context provider.


This way to useContext change html lang='vi' to lang='en' in layout.tsx


Firts please see structure:



I has created 2 file: context.tsx, child.tsx

Make a context.tsx:



import { Context } to child.tsx




Please see a page.tsx



import { Context } and wrap …

change child components context current function html language next.js provider react returns usecontext value

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Associate Data Engineer

@ Nominet | Oxford/ Hybrid, GB

Data Science Senior Associate

@ JPMorgan Chase & Co. | Bengaluru, Karnataka, India