0

When we use the npm package reselect (with React), we may do

export const someData = createSelector(
  objs,
  (objs) => {
    // ...
});

and I think someData is actually a function? But inside of our Component's .jsx file, we could show it as:

{someData[0].countThumbUp}

so it is somewhat strange, when someData is a function, but we can somehow treat it as an array. How does it work?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • Reselect is typically used for selecting (hence the name) from a state tree object BEFORE being passed into a react component. It is a function which you must call prior to passing the returned value into the react component as a property, so you would not be referencing the function inside your component at all, it would simply receive the data returned by the selector as a prop. It possible that `someData` inside your component is actually an array returned by a previous call to the selector of the same name. Although without seeing the rest of the component code I can't say for sure – alechill Jul 05 '17 at 14:13
  • `createSelector` returns a `Selector` (can be seen here: https://github.com/reactjs/reselect/blob/master/src/index.d.ts#L3) which is a function. So `{someData[0].countThumbUp}` shouldn't be possible. Can you show more of your code? – Alex Nov 20 '17 at 08:45

0 Answers0