Injecting MobX State Tree store into react components throwing error
up vote
0
down vote
favorite
Issue: I am getting an error when attempting to inject a MST store into react class component:
Error: Uncaught [Error: MobX injector: Store 'auth' is not available! Make sure it is provided by some Provider
the error stems from the LoginForm component posted below, and is nested under another component (not sure if this is the issue, as to say each component needs a <Provider>?)
component hierarchy:
Application (contains no Provider)
|__ Authentication (contains no Provider)
|__LoginForm
a little code:
import { AuthenticationStore } from './stores/AuthenticationStore'
const auth = AuthenticationStore.create()
ReactDOM.render(
<Provider auth={auth}>
<Application />
</Provider>,
document.getElementById('root')
);
//Application
const Application = inject('auth')(observer(class Application extends
Component {
render() {
console.log(this.props.auth) // logs the store as expected
return (
<div className={styles.applicationContainer}>
<Authentication/>
</div>
)
}
}))
export default Application
// LoginForm
const LoginForm = inject('auth')(observer(class LoginForm extends Component {
render() {
return (
<div></div>
)
}
}))
export default LoginForm
and to the question:
If not this, what is the preferred protocol for passing the store to child components (without passing as props)?
As always, thanks in advance for any and all input. If this is a duplicate (I couldn't find this particular error), please mark as such and I will update accordingly...
reactjs create-react-app mobx-react mobx-state-tree
add a comment |
up vote
0
down vote
favorite
Issue: I am getting an error when attempting to inject a MST store into react class component:
Error: Uncaught [Error: MobX injector: Store 'auth' is not available! Make sure it is provided by some Provider
the error stems from the LoginForm component posted below, and is nested under another component (not sure if this is the issue, as to say each component needs a <Provider>?)
component hierarchy:
Application (contains no Provider)
|__ Authentication (contains no Provider)
|__LoginForm
a little code:
import { AuthenticationStore } from './stores/AuthenticationStore'
const auth = AuthenticationStore.create()
ReactDOM.render(
<Provider auth={auth}>
<Application />
</Provider>,
document.getElementById('root')
);
//Application
const Application = inject('auth')(observer(class Application extends
Component {
render() {
console.log(this.props.auth) // logs the store as expected
return (
<div className={styles.applicationContainer}>
<Authentication/>
</div>
)
}
}))
export default Application
// LoginForm
const LoginForm = inject('auth')(observer(class LoginForm extends Component {
render() {
return (
<div></div>
)
}
}))
export default LoginForm
and to the question:
If not this, what is the preferred protocol for passing the store to child components (without passing as props)?
As always, thanks in advance for any and all input. If this is a duplicate (I couldn't find this particular error), please mark as such and I will update accordingly...
reactjs create-react-app mobx-react mobx-state-tree
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
1
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
1
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Issue: I am getting an error when attempting to inject a MST store into react class component:
Error: Uncaught [Error: MobX injector: Store 'auth' is not available! Make sure it is provided by some Provider
the error stems from the LoginForm component posted below, and is nested under another component (not sure if this is the issue, as to say each component needs a <Provider>?)
component hierarchy:
Application (contains no Provider)
|__ Authentication (contains no Provider)
|__LoginForm
a little code:
import { AuthenticationStore } from './stores/AuthenticationStore'
const auth = AuthenticationStore.create()
ReactDOM.render(
<Provider auth={auth}>
<Application />
</Provider>,
document.getElementById('root')
);
//Application
const Application = inject('auth')(observer(class Application extends
Component {
render() {
console.log(this.props.auth) // logs the store as expected
return (
<div className={styles.applicationContainer}>
<Authentication/>
</div>
)
}
}))
export default Application
// LoginForm
const LoginForm = inject('auth')(observer(class LoginForm extends Component {
render() {
return (
<div></div>
)
}
}))
export default LoginForm
and to the question:
If not this, what is the preferred protocol for passing the store to child components (without passing as props)?
As always, thanks in advance for any and all input. If this is a duplicate (I couldn't find this particular error), please mark as such and I will update accordingly...
reactjs create-react-app mobx-react mobx-state-tree
Issue: I am getting an error when attempting to inject a MST store into react class component:
Error: Uncaught [Error: MobX injector: Store 'auth' is not available! Make sure it is provided by some Provider
the error stems from the LoginForm component posted below, and is nested under another component (not sure if this is the issue, as to say each component needs a <Provider>?)
component hierarchy:
Application (contains no Provider)
|__ Authentication (contains no Provider)
|__LoginForm
a little code:
import { AuthenticationStore } from './stores/AuthenticationStore'
const auth = AuthenticationStore.create()
ReactDOM.render(
<Provider auth={auth}>
<Application />
</Provider>,
document.getElementById('root')
);
//Application
const Application = inject('auth')(observer(class Application extends
Component {
render() {
console.log(this.props.auth) // logs the store as expected
return (
<div className={styles.applicationContainer}>
<Authentication/>
</div>
)
}
}))
export default Application
// LoginForm
const LoginForm = inject('auth')(observer(class LoginForm extends Component {
render() {
return (
<div></div>
)
}
}))
export default LoginForm
and to the question:
If not this, what is the preferred protocol for passing the store to child components (without passing as props)?
As always, thanks in advance for any and all input. If this is a duplicate (I couldn't find this particular error), please mark as such and I will update accordingly...
reactjs create-react-app mobx-react mobx-state-tree
reactjs create-react-app mobx-react mobx-state-tree
asked Nov 8 at 21:58
studiobrain
3041416
3041416
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
1
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
1
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43
add a comment |
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
1
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
1
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
1
1
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
1
1
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216783%2finjecting-mobx-state-tree-store-into-react-components-throwing-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The code in your question looks sound to me. Do you think you could create a Minimal, Complete, and Verifiable example in e.g. CodeSandbox?
– Tholle
Nov 8 at 22:03
lemi try and spin one up
– studiobrain
Nov 8 at 22:15
1
Well, this is obviously something else on my end, tests I assume: codesandbox.io/s/9l5z2ox37y
– studiobrain
Nov 8 at 22:33
1
YES! Confirmation, it is in my tests not liking the Provider...
– studiobrain
Nov 8 at 22:43