1
0
Fork 0

fix(org): Async method in useEffect

This commit is contained in:
Joost De Cock 2022-07-10 16:35:05 +02:00
parent 8075a043a8
commit fdcd57e177

View file

@ -22,6 +22,22 @@ const Difficulty = ({ score=1 }) => {
return icons
}
const loadDesign = async (design, setExamples) => {
// Strapi filtering syntax
const url = `${strapiHost}/showcaseposts?_locale=en&_sort=date:DESC` +
`&_where[_or][0][design1_eq]=${design}` +
`&_where[_or][1][design2_eq]=${design}` +
`&_where[_or][2][design3_eq]=${design}` +
`&_limit=5`
await fetch(url)
.then(response => response.json())
.then(data => setExamples(data.map(post => ({
slug: `/showcase/${post.slug}`,
img: `${strapiHost}${post.image.formats.thumbnail.url}`,
title: post.title
}))))
.catch(err => console.log(err))
}
const Design = ({ design }) => {
const { t } = useTranslation(['patterns'])
@ -32,22 +48,9 @@ const Design = ({ design }) => {
const [examples, setExamples] = useState([])
useEffect(async () => {
// Strapi filtering syntax
const url = `${strapiHost}/showcaseposts?_locale=en&_sort=date:DESC` +
`&_where[_or][0][design1_eq]=${design}` +
`&_where[_or][1][design2_eq]=${design}` +
`&_where[_or][2][design3_eq]=${design}` +
`&_limit=5`
await fetch(url)
.then(response => response.json())
.then(data => setExamples(data.map(post => ({
slug: `/showcase/${post.slug}`,
img: `${strapiHost}${post.image.formats.thumbnail.url}`,
title: post.title
}))))
.catch(err => console.log(err))
}, [ design ])
useEffect(() => {
loadDesign(design, setExamples)
}, [ design, setExamples ])
return (
<div className={`