Question about useGlobalConfig

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!

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.

Thanks @kuovonne ! That worked.

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.