Skip to content

Commit e1e9215

Browse files
implement context value on header
1 parent caa6ccc commit e1e9215

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/code/CodeOptions.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const CodeOptions = ({ children }) => {
6060
width="fit-content"
6161
sx={selectStyles}
6262
onChange={(e) => setLanguagePreset(e.target.value)}
63-
defaultValue={languagePreset}
63+
value={languagePreset}
6464
>
6565
<option value="JS">JS</option>
6666
<option value="TS">TS</option>

src/components/navs/Header.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { TiStarFullOutline } from "react-icons/ti";
2222
import { useStars } from '../../hooks/useStars';
2323
import { useDeviceOS } from 'react-haiku';
2424
import { useSearch } from '../context/SearchContext/useSearch';
25+
import { useLanguage } from '../context/LanguageContext/useLanguage'
2526

2627

2728
import Logo from '../../assets/logos/reactbits-logo.svg';
@@ -31,6 +32,7 @@ import FadeContent from '../../content/Animations/FadeContent/FadeContent';
3132
const Header = () => {
3233
const { isOpen, onOpen, onClose } = useDisclosure();
3334
const { toggleSearch } = useSearch();
35+
const { languagePreset, setLanguagePreset } = useLanguage();
3436
const stars = useStars();
3537
const os = useDeviceOS();
3638

@@ -84,8 +86,8 @@ const Header = () => {
8486
rounded="xl"
8587
width="fit-content"
8688
fontWeight={600}
87-
onChange={(e) => localStorage.setItem('preferredLanguage', e.target.value)}
88-
defaultValue={localStorage.getItem('preferredLanguage') || 'JS'}
89+
onChange={(e) => setLanguagePreset(e.target.value)}
90+
value={languagePreset}
8991
>
9092
<option value="JS">JS</option>
9193
<option value="TS">TS</option>

0 commit comments

Comments
 (0)