I'm fairly new to React and am currently working on changing a functional component to a class, however I'm receiving the following error:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
This appears to relate to line 11:
const { choices, setChoices } = useContext(ChoicesContext); Any help would be much appreacited.
import React, { useContext } from "react"; import { Link } from "react-router-dom"; import CategoryData from "./data/CategoryData"; import { ChoicesContext } from "../context/ChoicesProvider"; import { ReactComponent as Logo } from '../images/logo.svg'; import { ReactComponent as WaterTechLogo } from '../images/water-tech-logo.svg'; class Applications extends React.Component { render() { const { choices, setChoices } = useContext(ChoicesContext); return ( <> <Link to="/"> <Logo className="Logo" /> </Link> <WaterTechLogo className="WaterTechLogo" /> <div className="pageLinks"> <div className="breadcrumb">Applications</div> <div className="backBtn"></div> </div> <div className="applications wrapper d-md-flex"> <aside> <h2>Select an<br />Application</h2> </aside> <main> <div id="applicationsList"> {CategoryData.map((cat, i) => ( <div key={i} className="application"> <Link onClick={() => setChoices({ ...choices, category: cat.name })} to={{ pathname: "/waterType", name: cat.name, }} > <img src={cat.imageURL} alt={cat.name} /> <h4 className="appTitle">{cat.name}</h4> </Link> </div> ))} </div> </main> </div> </> ); } } export default Applications;