Help

Error with code example in tutorial

Topic Labels: Custom Extensions
1480 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Holly_Gronau
5 - Automation Enthusiast
5 - Automation Enthusiast

Using this tutorial there is a small error that we got stuck on in part 4.

We ended up editing it this way I am sure something more elegant is what you guys had in mind. This is just an example.

function TodoBlock() {
    // YOUR CODE GOES HERE
    const base = useBase();
    const globalConfig = useGlobalConfig();
    const tableId = globalConfig.get('selectedTableId');
    const completedFieldId = globalConfig.get('completedFieldId');
    const table = base.getTableByIdIfExists(tableId);
    const completedField = table ? table.getFieldByIdIfExists(completedFieldId) : null;
    const toggle = (record) => {
        table.updateRecordAsync(
            record, {[completedFieldId]: !record.getCellValue(completedField)}
        );
    };    
    const records = useRecords(table);
    const tasks = records && completedField ? records.map(record => (
        <Task key={record.id} record={record} onToggle={toggle} completedFieldId={completedField} />
   )) : null;
    return (
        <div>
            <TablePickerSynced globalConfigKey="selectedTableId" />
            <FieldPickerSynced table={table} globalConfigKey="completedFieldId" />
            {tasks}
        </div>
    )
}
2 Replies 2
Billy_Littlefie
7 - App Architect
7 - App Architect

Hi @Holly_Gronau,

Thanks for writing in! Looking now, I see that there is a duplicate <TablePicker> in the sample code listed in the guide at this section. Is this the error you’re describing, or was it something else?

I’ll get a patch up for the duplicate <TablePicker> in any case, thanks for flagging!

Yes, thanks I am glad I posted this the community here seems very nice and super helpful. I have only been working on the custom block beta code since monday and so far it’s been really great so I just wanted to pass this along so no one else get’s stuck.

We are creating a custom block for sending data from airtable to Sanity.io similar to some of the custom wordpress blocks people have already created. If you know of anyone where who has attempted this with Sanity.io and posted please let me know if not if you are interested in our progress on this I am happy to post how it is going too.