1

I try to load the ID from a ble device via AsyncStorage that I save in a another component. But then I do this I get the following error:

ExceptionsManager.js:65 Cannot read property 'loadMac' of undefined

This is my loadMac() function:

   export function loadMac() {
  AsyncStorage.getItem(MAC_KEY)
    .then((item) => {
      console.log(item);
      return item;
    })
    .catch((error) => {
      console.log(error);
    });
}

And I call this function in my component like this:

store.loadMac();

Then I try

AsyncStorage.getItem(MAC_KEY)
  .then((item) => {
      console.log(item)});

I will get my ID.. but not from my function that I have in another file.

Any solution ?

4
  • store is not defined when you are calling store.loadMac(); Commented Sep 8, 2017 at 0:51
  • you've not shown how store would be possibly defined as anything Commented Sep 8, 2017 at 1:04
  • What is store? Did you import the function as store? If you imported the loadMac module as store, you just call store() Commented Sep 8, 2017 at 1:27
  • This is how I import my store => const store = require('../../api/store'); EDIT: Ok sorry I forget this import in my other component <.< Commented Sep 8, 2017 at 2:11

1 Answer 1

2

The error message says store is not defined, so you should look for a solution checking it. By the code you posted I am assuming you've tried to have 2 different components: one stateless component named 'store' which you are exporting to access its' loadMac function. And another where you are importing the 'store' component. Correct me if I'm wrong. If this is the case, your export syntax is incorrect. It should be something similar to this

export default const Store = () => {...}

And then import it like this:

import Store from './yourPathToStore';

If it's not, then you shouldn't have that export and also clarify what is exactly your 'store'.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Jeah you right, I forget the import, had this only in one component <.<

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.