If using the new style context, re-declare this in your class to be the
React.ContextType
of your static contextType
.
Should be used with type annotation or static contextType.
static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>
If set, this.context
will be set at runtime to the current value of the given Context.
Usage:
type MyContext = number
const Ctx = React.createContext<MyContext>(0)
class Foo extends React.Component {
static contextType = Ctx
context!: React.ContextType<typeof Ctx>
render () {
return <>My context's value: {this.context}</>;
}
}
Generated using TypeDoc
UseSignal provides a way to hook up a Phosphor signal to a React element, so that the element is re-rendered every time the signal fires.
It is implemented through the "render props" technique, using the
children
prop as a function to render, so that it can be used either as a prop or as a child of this element https://reactjs.org/docs/render-props.htmlExample as child:
Example as prop: