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.

Prop values in selectors - retrieving via an inline selector doesn't seem to work correctly

See original GitHub issue

We are attempting to use a Prop inside of a Selector.

We’re following this suggestion:

However, for whatever reason, we cannot seem to get access to props inside the inline selector as described in the documentation.

Here is a quick snippet I built on to illustrate the issue.

require("react/package.json"); // react is a peer dependency. 

require ("react-dom");

require("react-redux/package.json"); // react-redux is a peer dependency. 

require("redux/package.json"); // redux is a peer dependency. 

require("reselect/package.json"); // reselect is a peer dependency. 
var kea = require("kea")

const logic = kea.kea({ 
  selectors: ({ props }) => ({
        valueFromSelectorsProps: [
            () => [],
            () =>
        valueFromInlineSelectorProps: [
            () => [
                // inlineProps is an empty object here, it should be the props which I passed into the 'build' method
                (_, inlineProps) =>
            (foo) => foo
}){ foo: 'foo' })

// "foo" --- It works!

// undefined --- It doesn't seem to work!

As you can see, I attempt to use the 2 different methods of accessing props as described in the docs. Both should work, right? For whatever reason though, I cannot get inline selector method to work.

Anyone have a second to take a look at this? Could just be user error.

Issue Analytics

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

github_iconTop GitHub Comments

mariusandracommented, Apr 16, 2021

Fixed in 2.3.5 😃

Turns out .mount() was basically calling .build().mount() and the default props in .build(props = {}).mount() were overriding the ones stored on the built logic. Since no other test broke, I just released the fix in a patch version.

The const instance = approach makes sense if you’re using keyed logic. Then each instance will have a different set of props attached to it.

And thanks for all the warm feedback! 😊

mariusandracommented, Apr 5, 2021

Hey, that’s indeed the right approach. If you call logic.mount(), it’ll basically run{}).mount() behind the scenes, thus resetting the props you gave with{ foo: 'foo' }) just one line earlier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attribute selectors - CSS: Cascading Style Sheets | MDN
The CSS attribute selector matches elements based on the presence or value of a given attribute.
Read more >
not(:empty) CSS selector is not working? - Stack Overflow
Being a void element, an <input> element is considered empty by the HTML definition of "empty", since the content model of all void...
Read more >
How to Troubleshoot CSS Not Working - WPForms
There are a few common issues that can cause CSS not to appear correctly on a site. In this tutorial, we'll walk through...
Read more >
[attribute] | CSS-Tricks
We can use any of an element's attributes as selectors. ... Here, the selector matches a value that is either the only value...
Read more >
CSS - Cascading Style Sheets, designing for the Web - W3C
Also, you can pretty much trust that most browsers will display the content of an h1 element using a big font size... at...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found