Skip to content

Instantly share code, notes, and snippets.

@andrzejewsky
Created March 2, 2019 13:36
Show Gist options
  • Save andrzejewsky/41512251e0c97f3f01f718e51232733a to your computer and use it in GitHub Desktop.
Save andrzejewsky/41512251e0c97f3f01f718e51232733a to your computer and use it in GitHub Desktop.
Netflix slider item
import React from 'react';
import cx from 'classnames';
import SliderContext from './context'
import ShowDetailsButton from './ShowDetailsButton'
import Mark from './Mark'
import './Item.scss'
const Item = ({ movie }) => (
<SliderContext.Consumer>
{({ onSelectSlide, currentSlide, elementRef }) => {
const isActive = currentSlide && currentSlide.id === movie.id;
return (
<div
ref={elementRef}
className={cx('item', {
'item--open': isActive,
})}
>
<img src={movie.image} alt="" />
<ShowDetailsButton onClick={() => onSelectSlide(movie)} />
{isActive && <Mark />}
</div>
);
}}
</SliderContext.Consumer>
);
export default Item;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment