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...










share|improve this question






















  • 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















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...










share|improve this question






















  • 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













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...










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings