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.

Computed runtime arguments not working

See original GitHub issue

I have a computed defined like this…

getBase64Video: computed([state => state.video], video => {
      return botid => {
        try {
          let b64 = btoa(video[botid].image);
          return `data:image/jpeg;base64,${b64}`;
        } catch (e) {
          console.log(e);
        }
      };
    })

And I get the error hooks.js:42 Uncaught Error: An error occurred trying to map state in a useStoreState hook: state.bots.getBase64Video is not a function. when I try calling it with let video = useStoreState(state => state.bots.getBase64Video(props.botid));

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
HZahrancommented, Aug 7, 2019

@pranaypratyush Actually i had the exact same issue before with both redux-persist and computed fields in which i did the same approach of using redux-persist-transform-filter at the end

However after installing the latest version 3.0.1 and tried adding a computed field to the white list, it’s working properly now.

Here’s my config inside the createStore() function

createStore(rootReducer, {
//...some config,
reducerEnhancer: reducer => {
    return persistReducer(
      {
        key: "store",
        storage,
        whitelist: ["auth", "user"], 
        stateReconciler: autoMergeLevel2,
        transforms: [
          createWhitelistFilter("auth", [
            "accessToken.data",
            "loginType",
            "isLoggedIn"
          ]),
          createWhitelistFilter("user", ["details.data"])
        ]
      },
      reducer
    );
  }
}

isLoggedIn is the computed field and is being persisted and re-hydrated properly now.

0reactions
pranaypratyushcommented, Aug 6, 2019

The problem is specifically that if a computed returns a function then redux-persist with cause problems with it. I used redux-persist-transform-filter to filter it out and there are no problems now. In fact, I would want a way for redux-persist to ignore all computed fields.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I pass parameters in computed properties in Vue.Js
Should I be using methods for such cases? No, you can't pass parameters to computed properties. Yes, using methods is the easiest way...
Read more >
Cache system for getters with arguments #777 - vuejs/vuex
When I do this with one getter function to which I feed the item ID as argument, the vue caching does not work,...
Read more >
Pass runtime arguments in an execution request | Workflows
You can pass runtime arguments in a workflow execution request and access those arguments using workflow variables.
Read more >
Computeds with arguments · MobX
1. Derivations don't need to be computed ... A function doesn't need to be marked as computed in order for MobX to track...
Read more >
Main() and command-line arguments | Microsoft Learn
If no arguments are supplied, the application issues a message that explains the correct usage of the program. To compile and run the ......
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