I am using our cartContext in a functional component like this:
import { CartContext } from '../../contexts/CartContext';
function staticCart(){
const { increase, decrease, removeProduct } = useContext(CartContext);
const { total, cartItems, shipping, netTotal, vat, finalTotal } = useContext(CartContext);
return (
<React.Fragment>Logic to use the complex cart contexts</React.Fragment>
)
}
And this working fine as expected. And we have a class-based component, which looks like this:
import- statements
class StaticCart extends COmponent<RouteComponentProps<any>, State> {
protected datatypes
constructor(props: any) {
...
}
componentDidMount() {
...
}
render() {
return (
<React.Fragment>
...
</React.Fragment>
)
}
}
I am trying to add the above same method(as in functional components) to the class Components.
I have tried:
- Using as static type as mentioned here: https://www.taniarascia.com/using-context-api-in-react/#class-component
- Place contexts in an external function based file, getting some other error
- Placing the contexts inside Render But nothing seems to work. I am highly confused of the docs present, so any help would be great.