javascript - Limit results from Reducer -


so reducer is:

const initialstate = {   1: {      id: '1',      user: 'user1',      text: 'dummy text id1',      somefiled: 'somevalue',     },   2: {      id: '2',      user: 'user1',      text: 'dummy text id2',      somefiled: 'somevalue',     },   3: {      id: '3',      user: 'user1',      text: 'dummy text id3',      somefiled: 'somevalue',     },   4: {      id: '4',      user: 'user1',      text: 'dummy text id4',      somefiled: 'somevalue',     },   5: {      id: '5',      user: 'user1',      text: 'dummy text id5',      somefiled: 'somevalue',     } } 

i've mapstatetoprops prop users , able show data:

const rendata = object.keys(this.props.users).map((key, idx) => { let user = this.props.users[key]  return(      <view key={idx} style={styles.mystyle}>          <text style={styles.mystyletext}>              { user.id } - { user.user } - { user.text }          </text>      </view>      ) }); 

i want show 2 objects reducer. first (id: '1') , second (id: '2') not based on id, first 2. , have button onpress load more 2 values. , if there more values, button show, else not show. not worried display of button now. want know how apply limit in rendering values reducer.

many thanks.

you have use slice method.

the slice() method returns shallow copy of portion of array new array object selected begin end (end not included). original array not modified.

let size=2; const rendata = object.keys(this.props.users).slice(0,size).map((key, idx) => { let user = this.props.users[key]  return(      <view key={idx} style={styles.mystyle}>          <text style={styles.mystyletext}>              { user.id } - { user.user } - { user.text }          </text>      </view>      ) }); 

you can declare object in state of component:

this.state={     data:{        count:count,        dataarray:array     } } 

and use setstate method in order bind values.

this.setstate({   data: {         count:newcount         dataarray: newarray        } }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -