I have a textarea, I created a preview div which only displays the text, but I want the text to have background color of grey when the sentence is between `` to display codes.
<textarea onChange={handleChange}></textarea>
I have a div which contains pre and code block.
<div>
<pre>{preview}</pre>
<code>{code}</code>
</div>
my handleChange function is:
const handleChange = (e) =>{
e.preventDefault()
setDescription(e.target.value)
setPreview(e.target.value);
if (e.key === '`'){
setCode(e.target.value)
}
}
Here, Code and preview are defined using useState
const [preview, setPreview] = useState("");
const [code, setCode] = useState("");
Is there any way I can accomplish it?