I have a global variable in the window object in a functional React component.
It's Global --> Designer --> nodes --> NODE_FORM --> props --> dataSource deep. How can I access it in my functional component?
CodePudding user response:
Global variables are bad design within react. Use Context instead https://reactjs.org/docs/context.html
CodePudding user response:
Y would you? It doesnt make any sense. Alot of anti patterns at onces. But the way of doing It Is
Global === Window
const Comp = props => {
const [get, set]= React.useState("");
React.useEffect(()=>{
set(window.Designer.nodes.NODE_FROM.dataSource);
},[window.Designer]);
return (<div/>)
};