Answer the question
In order to leave comments, you need to log in
How to change hash with input (React)?
There is a functional component, it has a Switcher component, under the hood of which is input type="checkbox". How to change hash value with input in React? In JS, you could do a trick with your ears, ...something like this:
location.href = window.location.pathname + '#' + lang;
But in React, such a trick will not work.
export default function Component() {
let [lang, setLang] = useState('en');
const chooseLang = (e) => {
setLang(e.target.checked ? (lang = 'ua') : (lang = 'en'));
};
// location.href = window.location.pathname + '#' + lang;
return (
<section id='setting'>
<Switcher
id='lang'
title='Language'
label_lt='English'
label_rt='Українська'
value={lang}
onClick={chooseLang}
/>
</section>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question