Just so you know, my Javascript is not that great. Can't write it fluently as I'd like to due to work loads and priorities. So I set out to writing this in vanilla JS instead of using a framework like React or VueJS. Just so it can sink into my head of what I'm typing.
Fetching data has become quite the ideal thing to do when you're working with a CMS via headless. Just means you're fetching the endpoints of a rest api and its usually in a JSON format similar to most arrays that you see in JS.
Real Case Scenario
There are many examples that you can find on the internet to fetch and to slice your data. Oh yes, btw slicing just means you start at a certain array and end. The argument is like this (2, 4) , means start at the 3rd article up to the 5th article. Very similar to offsetting your data.
Back to the scenario, say your client wants to show a couple of featured content displaying it in a card fashion with a break with one of their banner pictures. Then, the next line continues with the small chunks of the featured content from xyz category. Which looks like this on the frontend.
Here’s the Vanilla JS:

As I stated earlier, you can do this in VueJS, React or any other js framework. But if it makes sense to use a lighter version. Why not just write it in vanilla js.
Comments
Post a Comment