Reputation: 103
i have a function, in which i am using a useState hook on a variable named active
. This variable takes a string value, and on click it takes the value of the category which is clicked on. My goal is to use this value of category outside the function in order to perform operations on that particular category.
Is there a way in which i can export the value which this active
useState variable has, outside this function anywhere in the project.
the structure of my code is as follows:
export const funct = () => {
// useState variable that will take the value of category that it gets clicked on/
const [active, setActive] = useState('');
return (
<div className='abc'>
{
content.map((info) =>
// Card is the category card which has a string value associated with, i.e. (info.name)
<Card key={info.name} cardInfo={info} state={active} onClick={() => setActiveState(info.name)} />)
}
</div>
)
}
any help would be appreciated. thank you
Upvotes: 0
Views: 2361
Reputation: 7717
Depending on what you mean by "outside" the function there are generally 4 solutions.
Upvotes: 1