question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access an already created store?

See original GitHub issue

Think I must be missing something here, so I apologise if that is the case, but I am trying to access to store after it is created. Mainly to allow me to add/modify (store.addModel) the model dynamically.

I was trying to simply use the easy-peasy context (easy-peasy/src/context) with useContext(), but that doesn’t seem to work…

import StoreContext from 'easy-peasy/src/context'
// in my component...
const store = useContext(StoreContext)

The store var is always undefined 😖

Any help would be appreciated, as it is late here and I’m tired, so am probably missing something obvious.

thx

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ctrlplusbcommented, Oct 1, 2019

Released in v3.1.0

👍

2reactions
allprocommented, Sep 13, 2019

In my app, I have a createStore.js file,. When I create the store, I set a module-level store var, and also export a getStore() method that returns the store var. I can access this helper from anywhere, including services that are outside of React context. Pseudo-code…

// createStore.js
let store;

export default function createStore(state) {
  store = ....
  return store;
}

export const getStore = () => store;

// myService.js
import { getStore } from 'src/data/store';

function myService(data) {
  const store = getStore();
  ...

I also export a createTestStore() that accepts an object with useful {optional} params like data, model and api to simplify testing. This also sets the store var so that all code using getStore() works inside tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a database in Access
Open Access. If Access is already open, select File > New. · Select Blank database, or select a template. · Enter a name...
Read more >
How to create store database on MS Access 2010 - YouTube
Subject: Information TechnologyCourse ID : 01219112Section : 450Student ID : 5610545722 [SKE11 KU]
Read more >
How to access store in different component?
So I have a search bar where I store the queries with redux, which seems to work. I am now trying to access...
Read more >
Accessing the Store | React Redux
Accessing the Store. React Redux provides APIs that allow your components to dispatch actions and subscribe to data updates from the store.
Read more >
Access the Redux Store Outside a React Component
Here you are creating the store as you usually would, but then you are also exporting it. This will make it available to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found