useParentSpace
A React hook that returns the parent space for the current store context.
Arguments
options
(Object): An optional object to supply the following options:context
(React.Context|Object): Override the React Context used for accessing the store.
Returns
(Object): The parent store, or the current store if the current store has no parent.
Examples
import React from 'react'
import { useParentSpace } from 'react-redux-subspace'
const MyComponent = () => {
const parentSpace = useParentSpace()
const { parentValue } = parentSpace.getState()
return (
<div>
<p>{parentValue}</p>
<button onClick={() => parentSpace.dispatch({ type: "PARENT_ACTION" })}></button>
<div>
)
}
import React from 'react'
import { useParentSpace } from 'react-redux-subspace'
const CustomReduxContext = React.createContext()
const MyComponent = () => {
const parentSpace = useParentSpace({ context: CustomReduxContext })
const { parentValue } = parentSpace.getState()
return (
<div>
<p>{parentValue}</p>
<button onClick={() => parentSpace.dispatch({ type: "PARENT_ACTION" })}></button>
<div>
)
}