我正在构建一个以 Supabase 作为后端的 React 应用程序。我想在 React 中显示我的几个 supabase 表中的内容。但是,我承诺会提取这些数据,但我不确定如何在 React 中显示它。下面是我的代码:
SupaBase API Call:
async function getData() {
const {data, other} = await getWriters().then(
function(response) {
for (var i = 0; i < response.length; i++) {
var writerInfo = {}
writerInfo['username'] = response[i].username
writerInfo['bio'] = response[i].bio
// console.log('Writer Name: ', response[i].username);
// console.log('Writer Bio: ', response[i].bio);
getTagIds(response[i].writerId).then(
function(response2) {
for (var j = 0; j < response2.length; j++) {
getTagNames(response2[j].tag_id).then(
function(response3) {
writerInfo['categories'] = []
// console.log('Categories: ')
for (var k = 0; k < response3.length; k++) {
// console.log(response3[k].tag_name)
writerInfo['categories'] = response3[k].tag_name
}
}
)
}
}
)
}
return writerInfo['username']
}
)
return data
}
反应代码:
export default function BrowsePage() {
const classes = useStyles();
const [listOfWriters, setListOfWriters] = useState({});
const fetchData = async () => {
setListOfWriters(getWriters())
}
console.log(getData())
return (
<Grid container spacing={3}>
<Grid item sm={12}>
<Navbar />
</Grid>
<Grid item xs={12} className={classes.root}>
{getData}
</Grid>
<Grid item sm={12}>
<Footer />
</Grid>
</Grid>
);
}