Help

Re: Question about useGlobalConfig

Solved
Jump to Solution
902 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Jim_Ramsey
4 - Data Explorer
4 - Data Explorer

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!

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

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.

See Solution in Thread

2 Replies 2
kuovonne
18 - Pluto
18 - Pluto

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.

Jim_Ramsey
4 - Data Explorer
4 - Data Explorer

Thanks @kuovonne ! That worked.