Question Details

No question body available.

Tags

javascript reactjs react-native react-context react-state

Answers (1)

Accepted Answer Available
Accepted Answer
April 29, 2025 Score: 5 Rep: 207,803 Quality: Expert Completeness: 80%

Issue

The problem here is that you have malformed the context value:

value={(appCompanyId, setAppCompany)}

The code, written this way, uses the Comma operator:

The comma (,) operator evaluates each of its operands (from left to right) and returns the value of the last operand. This is commonly used to provide multiple updaters to a for loop's afterthought.

setAppCompany itself is returned as the entire context value, and the consumers attempt to destructure property values from it what are undefined and not callable as functions.

Solution Suggestion

You should pass either an object or an array of values.

value={{ appCompanyId, setAppCompany }}

const { appCompanyId, setAppCompany } = useContext(CompanyContext);

or

value={[appCompanyId, setAppCompany]}

const [appCompanyId, setAppCompany] = useContext(CompanyContext);