Fetching from backend#26
Conversation
| if (query.trim() === '') { | ||
| setEventCount(defaultList.length) | ||
| setPageCount(1) | ||
| } else { |
There was a problem hiding this comment.
try writing code in an "early return" idea.
consider this with multiple cases, will be very clear.
if (case A || case B) { ... return }
if (case C) {... return}
if (case D) {... return}
compared to
if (A) { ...}
else if (B) {...}
else if (C) {...}
| const realQuery = query.toLowerCase() | ||
| const filtered = defaultList.filter((event) => { | ||
| return searchedCategories.some((type) => { | ||
| return event[type].toLowerCase().includes(realQuery) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
not truly understanding the use case here, but can try useMemo to return filtered as a value instead.
though after the latest react update we might no longer need all these KEK
| key={index} | ||
| title={event.name} | ||
| description={event.description} | ||
| imgPosition={index % 2 === 0 ? 'left' : 'right'} |
There was a problem hiding this comment.
notice how === 0 is not required here~
| // direct database queries. | ||
| export async function getStaticProps() { | ||
| try { | ||
| const res = await fetch('https://.../events') |
There was a problem hiding this comment.
could consider using a promise instead.
| console.error('Error fetching photos', error) | ||
| return { | ||
| props: { | ||
| carouselPhotos: [], |
There was a problem hiding this comment.
not very elegant but can handle errors by adding new props
carouselPhotos: {
data: [],
error: {
message: "unauthorised query"
status: 401
}
}
|
ok bye just happened to be on github after awhile so decided to drop by. have fun coding! |
Added fetch statements either in react hooks or using
getStaticProps