[React 19] Get context value in class component constructor
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
I updated version of react from 18.2.0 to 19.1.0 (@types/react to 19.1.6, @types/react-dom to 19.1.5).
After the update I received several components with such errors:
Argument of type 'typeof SplitCostDialog' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof SplitCostDialog' is not assignable to type 'ComponentClass<never, any>'.
Target signature provides too few arguments. Expected 2 or more, but got 1.
I found the reason. I use context in class constructor.
export class SplitCostDialog extends React.PureComponent<ISplitCostDialogProps, IState> {
static contextType = ResourcePlanContext;
declare context: IResourcePlanContext;
constructor(props: ISplitCostDialogProps, context: IResourcePlanContext) {
super(props);
const { scope, position } = context.modals.splitPositionCost;
this.state = { form: new SplitCostForm(scope, position) };
}
...
}
How can I use context inside a constructor after updating to version 19?
I didn't find the answer in the guide.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the React 19 upgrade guide linked in the issue and compare it with the reported class-component constructor example. Document how context access in constructors should be handled after the upgrade, including the relevant migration guidance, so the guide answers this case clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100