Skip to main content
Solved

Question about useGlobalConfig

  • March 20, 2022
  • 2 replies
  • 20 views

I’ve built an app that allows users in my base to select a record in a certain table. I’m using GlobalConfig to store the ID of that record.

However, when I first publish the app to my base I get an error because the GlobalConfig does not yet have an ID stored. So when do useRecordById, I get an error like this: “getRecordById expects a string” because there is no record ID stored in GlobalConfig, since a user has not yet selected one.

When I tried putting useRecordById inside a conditional, I get an error because you can’t put hooks inside a conditional.

What is the best way to get around this? Thanks!

Best answer by kuovonne

Welcome to the Airtable community! And welcome to writing a custom app.

Since the rule of hooks says to put a hook (such as useRecordById) only at the top level of a component, you should break your code up into different components. If there is a stored record, call a component with useRecordById. If there is no stored record, call a different component that lets the user pick the component.

2 replies

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • Answer
  • March 20, 2022

Welcome to the Airtable community! And welcome to writing a custom app.

Since the rule of hooks says to put a hook (such as useRecordById) only at the top level of a component, you should break your code up into different components. If there is a stored record, call a component with useRecordById. If there is no stored record, call a different component that lets the user pick the component.


  • Author
  • New Participant
  • 1 reply
  • March 21, 2022

Thanks @kuovonne ! That worked.