fix(org): Async method in useEffect
This commit is contained in:
parent
8075a043a8
commit
fdcd57e177
1 changed files with 19 additions and 16 deletions
|
@ -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={`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue