I am currently writing a React App, that should be able to rerender components when the value of any observable changes. The problem is, that I can't get email to rerender if it changes.
store.ts
export class ExampleStore {
@observable email = 'hello';
@action setEmail(email: string) {
this.email = email;
}
}
index.tsx
const stores = {
exampleStore
};
ReactDOM.render(
<Provider {...stores}>
<App />
</Provider>,
document.querySelector('#root')
);
App.tsx
interface Props {
exampleStore?: ExampleStore;
}
@inject('exampleStore')
@observer
export class App extends React.Component<Props, {}> {
componentDidMount() {
setInterval(() => {
this.props.exampleStore!.setEmail(Math.random() * 10 + '');
}, 2500);
}
render() {
const { email } = this.props.exampleStore!;
return <div>{email}</div>;
}
}
I have seen many examples use the useContext hook, but I have to use class components. I am not sure why this isn't calling the render function again. I have mobx and mobx-react installed.