Pagination lesson 4 show only 1 page

the issue is
const pagesCount = itemCount / pageSize;
“pagesCount” is NaN
i will try to figure out why as it should be 3 based on the logic in lesson 4
also props defined weard
image
the code:

const Pagination = props => {

const {itemCount,pageSize} = props;

 const pagesCount = itemCount / pageSize;

  const pages = _.range(1, pagesCount + 1);

return (

<nav>

    <div>{itemCount}</div>

    <ul className="pagination">

        {pages.map((page) => (

        <li key={page} className="page-item">

            <a className="page-link">{ page }</a>

            </li>

        ))}

        {/* <li className="page-item"><a class="page-link" href="#">Previous</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">1</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">2</a></li>

        <li className="page-item"><a class="page-link" href="#">3</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">Next</a></li> */}

    </ul>

</nav>

)

}

solved!
pagination:
const Pagination = props => {

const { itemsCount, pageSize } = props;

//  const pagesCount = props.children[1] / props.children[3];

 const pagesCount = itemsCount / pageSize;

  const pages = _.range(1, pagesCount + 1);

return (

<nav>

    <ul className="pagination">

        {pages.map((page) => (

        <li key={page} className="page-item">

            <a className="page-link">{ page }</a>

            </li>

        ))}

        {/* <li className="page-item"><a class="page-link" href="#">Previous</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">1</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">2</a></li>

        <li className="page-item"><a class="page-link" href="#">3</a></li> */}

        {/* <li className="page-item"><a class="page-link" href="#">Next</a></li> */}

    </ul>

</nav>

)

}

movies:
import React, { Component } from ‘react’;

import { getMovies } from ‘…/services/fakeMovieService’

import Like from ‘./common/like’;

import Pagination from ‘./common/pagination’;

class Movies extends Component {

state = {

        movies: getMovies(),

        pageSize: 4,

    };

handleDelete = (movie) => {

const movies = this.state.movies.filter(m => m._id !== movie._id)

// const removed = this.state.movies.filter(m => m._id === movie._id)

// console.log({removed})

this.setState({movies})

};

handleLike = (movie) => {

const movies = […this.state.movies];

const index = movies.indexOf(movie);

movies[index] = {…movies[index]}

movies[index].liked = !movies[index].liked;

this.setState({movies});

};

handlePageChange = (page) => {

console.log(page);

};

render() {

const countMovies = this.state.movies.length;

if (countMovies === 0) {

    return "There are no movies in database"

};



return (

    <>

    <p>There are {countMovies} movies in the database</p>

    <table className="table">

        <thead>

            <tr>

                <th>Title</th>

                <th>Genre</th>

                <th>Stock</th>

                <th>Rate</th>

                <th>Liked</th>

            </tr>

        </thead>

        <tbody>

            {this.state.movies.map((movie)=>(

            <tr key={movie._id}>

                <td>{movie.title}</td>

                <td>{movie.genre.name}</td>

                <td>{movie.numberInStock}</td>

                <td>{movie.dailyRentalRate}</td>

                <td><Like onClick={() => this.handleLike(movie)} liked={movie.liked}/></td>

                <td><button onClick={()=>this.handleDelete(movie)} className='btn btn-danger btn-sm'>Delete</button></td>

            </tr>

            ))}

        </tbody>

     </table>

    <Pagination

        itemsCount={countMovies}

        pageSize={this.state.pageSize}

        onPageChange={this.handlePageChange}>

    </Pagination>

     </>

    );

}

}

export default Movies;

Hi, I started doing the react course and in the Pagination Lesson -4, when I tried to install loadash in VS code I was shown weird errors and not able to install. I have tried installing npm i loadsh@4.17.10 and I got errors so I also tried installing npm i loadash@4.17.24 which is the latest version, still I got errors. Can you help me in solving this issue? below is the error I am getting both in cmd and VS code.

hi, ignore the errors
the problem is not there, im 100% sure that its in the code
i did it not long ago with the same issue
check the code, duplicate it exactly and it will work

Hi, I exactly copied the code and checked again. And below is the error that is shown in the browser. It is saying loadash module not found. just before the pagination step the app was working fine. So I am assuming there is some problem in installing Loadash.

did you imported it?

Yeah I imported it using " import _ from “loadash”; " on the top of pagination.jsx component

try “npm i lodash” then NOT “npm install lodash”
it worked for me as Mosh did but try it anyway

1 Like

Yep. Pretty sure the package is lodash not loadash.
It comes from low dash because it uses underscore ( _ ) and has nothing to do with any loading operation.
So just a typo.
We’ve all been there at some point.

1 Like