Closed
Description
It seems that ReSub swallows the context update on some specific use-case.
I'm having trouble using ReSub and React-Router, but I was able to reproduce it with just React.
The repro is the following:
import * as React from "react";
import { ComponentBase } from "resub";
import * as PropTypes from "prop-types";
class NotWorking extends ComponentBase<{}, {}> {
render() {
return <div>{this.props.children}</div>;
}
}
class Working extends React.Component {
render() {
return <div>{this.props.children}</div>;
}
}
class RenderFromContext extends React.Component {
static contextTypes = { text: PropTypes.string };
render() {
return this.context.text;
}
}
class MakeContext extends React.Component<
{},
{ text: string }
> {
state = {
text: "",
};
static childContextTypes = { text: PropTypes.string };
getChildContext() {
return { text: this.state.text };
}
componentDidMount() {
this.setState({ text: "Works" });
}
render() {
return <div>{this.props.children}</div>;
}
}
class App extends React.Component {
render() {
return (
<MakeContext>
Working:
<Working>
<RenderFromContext />
</Working>
Not working:
<NotWorking>
<RenderFromContext />
</NotWorking>
</MakeContext>
);
}
}
export default App;
If you'd like to run it on your browser I've made a create-react-app with this code and it is hosted here: https://github.com/degroote22/resubctxbug2
Just clone then npm install then npm start and you should see the following on your browser:
Working: Works Not working:
Thanks for your time 👍
Metadata
Metadata
Assignees
Labels
No labels