Recoil: Got TypeError: Object(...) is not a function when trying to import { selectorFamily } from "recoil"

Created on 18 May 2020  路  10Comments  路  Source: facebookexperimental/Recoil

Developer Story

As a developer
I want to use the selectorFamily helper function
So that I can make asynchronous queries with parameters

Description

I am trying to make an asynchronous data query with parameters. So I am trying to use the selectorFamily helper. But when I try to import { selectorFamily } from "recoil", the application throws TypeError: Object(...) is not a function.

How to fix it

Maybe exporting the selectorFamily helper at the recoil library.

Steps to reproduce the behavior

  1. Initialize or open a React project;
  2. Run npm install recoil --save-exact to install version 0.0.7;
  3. Create a JS file;
  4. Try to import { selectorFamily } from "recoil" in this file;
  5. Run npm start and check if error occurs.

Expected behavior

Application should not throw a TypeError.

Actual behavior

TypeError: Object(...) is not a function
Module.<anonymous>
src/recoil/selectors/reportedParkingsQuery.js:20
  17 |   throw error.response.error
  18 | }
  19 | 
> 20 | export const reportedParkingsQuery = selectorFamily({
  21 |   key: "ReportedParkings",
  22 |   get: (carPlate) => async ({ get }) => {
  23 |     const response = await getParkingsByCarPlate(carPlate)

Module../src/recoil/selectors/reportedParkingsQuery.js
http://localhost:8000/commons.js:120193:30
__webpack_require__
/webpack/bootstrap:789

Environment

  • OS: macOS Catalina 10.15.4 (19E287);
  • Node version: v12.16.0;
  • NPM version: 6.13.4;
  • React version: 16.13.1;
  • Recoil version: 0.0.7.

Related code

https://github.com/facebookexperimental/Recoil/blob/1e6e077de77e35dadf28b1a452980f2cb76620a5/src/recoil_values/Recoil_selectorFamily.js#L88-L135

bug

All 10 comments

selectorFamily isn't currently exported in published version on npm. Though, the code is there so you can explore using it directly. #33 should help fix the exporting issue for the open-source version.

Note that we want to keep the core API simple. So, optional helpers built on top of the core API are being exported in a RecoilUtils module.

@drarmstr thank you.

Since, for now, the code is not exported nicely with the build, does it make sense to put that information at selectorFamily at docs, and update it as #33 is fixed?

@jimmyandrade The code is available here, it's just not being exported nicely with the build. Thanks for bearing with us as we're getting the initial release of this beta library up and going.

Thank you for the support.

And, sorry, I didn't express myself well in the last comment. I've found the helper function code:

https://github.com/facebookexperimental/Recoil/blob/1e6e077de77e35dadf28b1a452980f2cb76620a5/src/recoil_values/Recoil_selectorFamily.js#L88-L135

Hey @jimmyandrade, sorry about that mis-match. We are pretty new at this. Anyway, selectorFamily is (for now) just a simple memoized function, although we will probably add some other tricks for memory management soonish. Hope that unblocked you for now?

Hey @davidmccabe! Don't worry, the work you people are doing is already helping a lot.

In fact, I still haven't been able to unlock what I need. I'm talking about it here: #178

@jimmyandrade Hey bro, do you already resolved this?

Is this the same issue for using atomFamily?

Hi there, thanks for the work on this library!

Is there an easy way to use selectorFamily in recoil currently? I have looked at #33 and #82 but it does not seem to be quite there yet...

@timeswind - Yes, same issue for atomFamily or any of the other utils

@Cadrach - Can you fork the repository instead of using the NPM package as a workaround for now? We're getting close, though..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pesterhazy picture pesterhazy  路  4Comments

Sawtaytoes picture Sawtaytoes  路  4Comments

ibnumusyaffa picture ibnumusyaffa  路  4Comments

thegauravthakur picture thegauravthakur  路  3Comments

julienJean99 picture julienJean99  路  3Comments