Documents / @faasjs/ant-design / AppContext
Variable: AppContext
constAppContext:object
Shared context storing message, notification, modal, and drawer helpers.
Type Declaration
use
use: <
NewT>(this) =>Readonly<NewT>
Hook used to read values from the splitting context.
Type Parameters
NewT
NewT extends useAppProps = useAppProps
Parameters
this
void
Returns
Readonly<NewT>
See
Example
function ChildComponent() {
const { value, setValue } = use()
return (
<div>
{value}
<button onClick={() => setValue(1)}>change value</button>
</div>
)
}
Provider()
Provider<
NewT>(this,props):ReactNode
The provider component of the splitting context.
Type Parameters
NewT
NewT extends useAppProps = useAppProps
Parameters
this
void
props
children
ReactNode
Descendant elements that should read from the split contexts.
initializeStates?
Partial<NewT>
Initial values converted into local state via useStates.
Each key produces both a state value and its matching setter using the
value / setValue naming convention.
Example
<Provider initializeStates={{ value: 0 }}>
<Child />
</Provider>
// `Child` can read `value` and `setValue`
memo?
true | Key[]
Memoization mode for children.
Default
false
Pass true to memoize without dependencies or an array to control the
deep-equality dependency list manually.
value?
Partial<NewT>
Partial context value supplied by the caller.
Returns
ReactNode
See
Example
function App() {
const [value, setValue] = useState(0)
return (
<Provider value={{ value, setValue }}>
<ReaderComponent />
<WriterComponent />
</Provider>
)
}
Example
const { message } = AppContext.use()