GeodooBlog App Development Series with React Native
GeodooBlog: pagination tactics
Hey there! How are you? I hope well!
Ok, here is the next thing I am searching for: how on Earth should I find out how many posts there are in the response I get which is already paginated at 10 posts every time?
WordPress did a fine job passing through the total number of posts and pages in the headers of the response! Just look out for this:
headers: { map: { allow: [ 'GET' ], 'x-wp-total': [ '45' ], 'x-wp-totalpages': [ '5' ], ... 'access-control-expose-headers': [ 'X-WP-Total, X-WP-TotalPages' ], link: [ '<http://geodoo.work/wp-json/wp/v2/posts?page=2>; rel="next"' ], ...
Nice and easy, huh? I have a total of 45 posts divided in 5 pages so far! Nice!
The only thing I have to do is find a way to pass those two variables over to the MainScreen component! The variables values are these (reading from the res parameter in the HTTP call):
res.headers.map['x-wp-total'][0] res.headers.map['x-wp-totalpages'][0]
After I find them I have to find the proper way to make the calls for the next pages of the posts!
NOTE: The official docs page is this where I first saw the two variables: