0

I have a React + Redux application and running with webpack. Currently in my application i have some small components developed by me. In some cases we should render Grid kind of components with hundreds of data. For some reasons i can not use paging. And when user clicks to edit button on my grid line item this will open a small dialog. In that window i have an input text element and if user edits input elements value for each key down this causes render all my page with all data and components. So for each keypress there is a lag about 1 second. How can i deal with this?

I am not using and DevTools My problem is rendering of my components need time. But in this case this is normal i think. I can not remove onChange from my input because it will become readonly. I have tried to use defaultValue but i will fill my props after render my component because that data coming from an api.

Code

  
    getEditSubWindow(){ 
            
        var gridData = this.props.stocks.filter(s=>{ return s.isSelected; });
           
        var windowCommandButtons=[
          {text:'Cancel', className:'cancel', onClick:null },
          {text:'Save', className:'save', onClick:null }
        ];
      
        return (
            <Window 
                header="Details"   
                windowButtons={['close']} 
                canDock={false}
                isDialog={true}
                onClose={::this.hideEditSubWindow}
                 >
                <Panel header="Details">
                  
                  <input type="text" placeholder="Information" value={this.props.currentData.name} onChange={::this.setInformation} onBlur={::this.saveInformation} /> 
          
                  <input type="text" placeholder="Information" defaultValue={this.props.currentData.name}  onBlur={::this.saveInformation} /> 
          
          
                </Panel> 
                
                {this.getGrid(gridData)}
            </Window> );
    }
    
    
    
     
    setInformation(event){  
      this.props.currentData.name= event.target.value;
      this.props.actions.informationChanged(this.props.currentData, event.target.value);  
    }
  


    saveInformation(event){
      this.props.actions.saveInformation(this.props.currentData, event.target.value);
    }
    


    render(){
      
      return   (
         <div className="stocks">
            {this.getGrid(this.props.stocks)}
            {this.state.showEditSubWindow?this.getEditSubWindow():null}
         </div>
      )
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    MY ACTIONS
    
export function requestStockList() {
    return (dispatch) => { 
      stock.getAll()
        .then(data => {dispatch(receiveStockList(data.stock));  } )
        .catch(error => { console.log(error) }); 
    }
}
  
export function saveInformation(info) {
    return (dispatch) => { 
      information.save(info)
        .then(data => {dispatch(receiveCurrentData(data.information));  } )
        .catch(error => { console.log(error) }); 
    }
}
export function informationChanged() {
    return (dispatch) => { 
      dispatch(receiveCurrentData(data.stock)); 
    }
}
  
export function receiveStockList(stockList) {
  return {
    type: RECEIVE_STOCKLIST,
    stockList
  };
}

export function receiveCurrentData(currentData) {
  return {
    type: CURRENTDATA_CHANGED,
    currentData
  };
}


    
  
  
  
  
  
  
  
  
  
  
  
  
  
  MY REDUCER
  
const initialState =  { 
  stockList:[], 
  currentData:{}
};

export default function StockReducer(state = initialState, action) {
   
  
     var newState = Object.assign({}, state);
  switch (action.type) {
    
    case actions.RECEIVE_STOCKLIST: 
        newState.stockList=action.stockList; 
      break;    
    case actions.CURRENTDATA_CHANGED: 
        newState.currentData=action.currentData;  
      break;    
      default:
      break;  
      
  }
    
  return newState;
  
}
ersin ceylan
  • 107
  • 1
  • 6
  • The lag is probably not in the code you shared. If render takes long, my first suspect would be the (apparently large) griddata. The result of `this.getGrid(gridData)`. If the grid is large, and rendering takes long, my bet would be you got your keys wrong, making react needlessly re-rendering the entire grid to the DOM. – wintvelt May 25 '16 at 11:35
  • Possible duplicate of [How to avoid re-rendering the whole List instead of adding the new item to the DOM list in react JS?](http://stackoverflow.com/questions/35308928/how-to-avoid-re-rendering-the-whole-list-instead-of-adding-the-new-item-to-the-d) – Paul Sweatte Sep 08 '16 at 17:18

0 Answers0