I am messing around with a simple trivia api trying to become more familiar with REACT. I noticed the question data is returning with special character codes. The react jsx is not liking it. What is a method to convert these characters easily?
The output should convert special characters ...
const App = () => {
return (
<>
<Header />
<TriviaQ />
</>
);
};
const Header = () => {
return <h1>Daily Trivia</h1>;
};
const TriviaQ = () => {
const path = "https://opentdb.com/api.php?amount=1";
const [trivia, setTrivia] = React.useState([]);
React.useEffect(() => {
async function getDat() {
const res = await fetch(path);
const data = await res.json();
console.log(data.results);
setTrivia(data.results);
}
getDat();
}, []);
return (
<div>
{trivia.map((d) => (
<div>
<Category type={d.category} />
<Question q={d.question} />
<Answer
wrong={d.incorrect_answers}
right={d.correct_answer}
questionType={d.type}
/>
</div>
))}
</div>
);
};
const Category = ({ type }) => {
return <div>{type}</div>;
};
const Question = ({ q }) => {
return <div>{q}</div>;
};
const Answer = ({ wrong, right, questionType }) => {
return (
<div>
{questionType === "boolean" && <div> TRUE OR FALSE</div>}
{questionType === "multiple" && <div>MULTIPLE CHOICE</div>}
</div>
);
};
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);