I’m tried to access only few values in my component but have to define all the values in useContext. if a am not defining the sequence its giving error
const [handleChange, isEditMode, setIsEditMode, partnerData, setPartnerData] = useContext(FilterContext);
here i want to use only two elements isEditmode and PartnerData
3
Answers
Create the context as an object and use curly braces to get just one property of it.
You can use
destructuring assignment
In order to access only two values from the
FilterContext
using useContext, you can destructure the values directly in theuseContext
function.You have to make sure that the
FilterContext
is properly defined and accessible within the component hierarchy.