Am trying to export or call two functions Eg. (teachers.js and student.js) that are link up to index.js but it throws error initializeBlock should only be called once.
If i tried to call the both at index.js as per below, it will not work.
initializeBlock(() => {<Teachers />; <Students />});
How do I solve this issue.
student.js
import {initializeBlock, useBase, useRecords, createRecordAsync, updateRecordAsync, updateRecordsAsync, table, useRecordIds} from '@airtable/blocks/ui';
import React, { Component } from "react";
import {base} from '@airtable/blocks';
function Students (){
const base = useBase();
const tab = base.getTableByNameIfExists('students_table');
const records = useRecords(tab);
return (
<ul>
<h1>Welcome to Students Records</h1> <br />
{records.map(record => {
return <li key={record.id}>{record.id}</li>
})}
</ul>
);
}
//initializeBlock(() => <Students />);
export default Students;
teachers.js
import {initializeBlock, useBase, useRecords,createRecordAsync, updateRecordAsync, updateRecordsAsync, table, useRecordIds} from '@airtable/blocks/ui';
import React, { Component } from "react";
import {base} from '@airtable/blocks';
function Teachers (){
const base = useBase();
const tab2 = base.getTableByNameIfExists('teachers_table');
const records = useRecords(tab2);
return (
<ul>
<h1>Welcome to Teachers Records</h1> <br />
{records.map(record => {
return <li key={record.id}>{record.id}</li>
})}
</ul>
);
}
//initializeBlock(() => <Teachers />);
export default Teachers;
index.js
import {
initializeBlock,
useBase,
useRecords,
} from '@airtable/blocks/ui';
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, HashRouter,Link, Switch } from 'react-router-dom';
import Teachers from './teachers';
import Students from './students';
class App extends Component {
render() {
return (
// rounting links goes here
);
}
}
//initializeBlock(() => {<Teachers />; <Students />});
export default App;