Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

redux filter movies list container

// MoviesContainer.js

import { connect } from 'react-redux';
import Movies from './Movies';

// Getting visible movies from state.
function getVisibleMovies(year, genre, rating, sorting, movies) {
  return movies
    .filter(m => {
      return (
        (year == 'all' || year == m.year) &&
        (genre == 'all' || genre == m.genre) &&
        (rating == 'all' || rating == m.rating)
      );
    })
    .sort((a, b) => {
      if (sorting == 'year') {
        return b.year - a.year;
      }
      if (sorting == 'rating') {
        return b.rating - a.rating;
      }
      if (sorting == 'alphabetically') {
        return a.title > b.title ? 1 : a.title < b.title ? -1 : 0;
      }
    });
}

function mapStateToProps(state) {
  const { year, genre, rating, sorting, movies } = state;
  return {
    movies: getVisibleMovies(year, genre, rating, sorting, movies),
  };
}

export default connect(mapStateToProps)(Movies);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Escaping special characters in JSON / list of invalid characters to strip from JSON string 
Javascript :: erb object to json 
Javascript :: how to get perticular 5 string element out of 10 from array javascript 
Javascript :: const toogleState = (index) ={ console.log(index); } 
Javascript :: javascript select element with pointer 
Javascript :: javascript .addListener( set custom parameters 
Javascript :: database number counter animation javascript from database 
Javascript :: matrix array javascript 
Javascript :: finnhub 
Javascript :: onload page data 
Javascript :: simple callback pattern 
Javascript :: count all items inside 2nd ul using jquery 
Javascript :: immediate invoke jquery function 
Javascript :: how to make a login form discord.js part 1 
Javascript :: rails hide field in json 
Javascript :: check if scrolled modal 
Javascript :: 4.7.1. The String Operator +¶ 
Javascript :: android studio select sim slot to send sms 
Javascript :: add single quote in Innerhtml javascript string 
Javascript :: react-leaflet/core/cjs/pane.js:7%20error15-Jun-2021%2000:45:06%20%20%20%20%20%20const%20pane%20=%20props.pane%20??%20context.pane; 
Javascript :: js regex replace unsafe regex 
Javascript :: 10.4.2. Functions // Default Value 
Javascript :: how to decrease the size of js files build from angular 
Javascript :: The attribute name of [ *ngFor ] must be in lowercase.(attr-lowercase) in VSCode 
Javascript :: RegEdt TimeAdj 
Javascript :: decode hex to string js 
Javascript :: fly: javascript fly 
Javascript :: matmenu in angular 
Javascript :: bootstrap off canvas not working 
Javascript :: react native expo PayloadTooLargeError: request entity too large 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =