Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

horizontal scrollview in react js

import React, { Component } from 'react';import ScrollMenu from 'react-horizontal-scrolling-menu';import './App.css'; // list of itemsconst list = [  { name: 'item1' },  { name: 'item2' },  { name: 'item3' },  { name: 'item4' },  { name: 'item5' },  { name: 'item6' },  { name: 'item7' },  { name: 'item8' },  { name: 'item9' }]; // One item component// selected prop will be passedconst MenuItem = ({text, selected}) => {  return <div    className={`menu-item ${selected ? 'active' : ''}`}    >{text}</div>;}; // All items component// Important! add unique keyexport const Menu = (list, selected) =>  list.map(el => {    const {name} = el;     return <MenuItem text={name} key={name} selected={selected} />;  });  const Arrow = ({ text, className }) => {  return (    <div      className={className}    >{text}</div>  );};  const ArrowLeft = Arrow({ text: '<', className: 'arrow-prev' });const ArrowRight = Arrow({ text: '>', className: 'arrow-next' }); const selected = 'item1'; class App extends Component {  constructor(props) {    super(props);    // call it again if items count changes    this.menuItems = Menu(list, selected);  }   state = {    selected  };   onSelect = key => {    this.setState({ selected: key });  }    render() {    const { selected } = this.state;    // Create menu from items    const menu = this.menuItems;     return (      <div className="App">        <ScrollMenu          data={menu}          arrowLeft={ArrowLeft}          arrowRight={ArrowRight}          selected={selected}          onSelect={this.onSelect}        />      </div>    );  }} 
Comment

PREVIOUS NEXT
Code Example
Javascript :: js element on mouse over 
Javascript :: javascript regex match sequence 
Javascript :: jquery if else click function 
Javascript :: concat js 
Javascript :: javascript bool 
Javascript :: exec in node js 
Javascript :: Add additional css class name in react app 
Javascript :: jquery slider 
Javascript :: next js link 
Javascript :: sort array based on multiple columns javascript 
Javascript :: angularjs 
Javascript :: export function javascript 
Javascript :: get query params 
Javascript :: json to yaml converter 
Javascript :: javascript sets 
Javascript :: for loop react 
Javascript :: flatlist inside flatlist react native 
Javascript :: convert a signed 64.64 bit fixed point number online 
Javascript :: Create a Counter Object or Map in javascript 
Javascript :: use cors 
Javascript :: nuxt custom plugin 
Javascript :: fsm2regex 
Javascript :: Javascript Unordered List HTML form Array 
Javascript :: es6 closures 
Javascript :: mongoose auto increment 
Javascript :: sortingDataAccessor 
Javascript :: Javascript code to Detect All Network Number In Nigeria (MTN, Glo, Airtel & 9Mobile). 
Javascript :: convert string to regular expression js 
Javascript :: tinymce editor description value is not getting onclick js 
Javascript :: remove green lines on google maps js 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =