ReactJs React linter warning: unused state field — while the state field is being used in setState reactjs react native,reactjs react native share code,reactjs react

I have an array of times in state I use to calculate an average time, also in state.

this.state = {
  avgTime: null,
  allTimes: []
}

then the method to do the calculation:

this.getTime = () => {
  this.setState((prevState) => {
    const timeDelta = Date.now() - this.state.startTime;
    prevState.allTimes.push(timeDelta);
    const factor = 10 ** -1;
    const avgTime = Math.round((prevState.allTimes.reduce((a, b) => a + b) /
      prevState.allTimes.length) * factor) / factor;
    return {
      avgTime,
      allTimes: prevState.allTimes,
    }
  })
}

My linter is warning me that allTimes is an unused state field, even though I use it in setState.

That leads me to believe this is a bad practice, but I'm not sure why. Is this something I should refactor, or just drop a linter exception and move on?

Answer:1



  1. reactjs react native
  2. reactjs react native share code
  3. reactjs react router
  4. reactjs react table
  5. reactjs react hooks
  6. reactjs react router dom
  7. reactjs react fragment
  8. reactjs react-router-dom example

I want to convert my <button> to a <Link>. But I keep getting an error. Warning: Failed prop type: Invalid prop `to` supplied to `Link`. My code looks like this. import React from '...

I want to convert my <button> to a <Link>. But I keep getting an error. Warning: Failed prop type: Invalid prop `to` supplied to `Link`. My code looks like this. import React from '...

I am trying to integrate react-select using redux form... Here is my code import Select from 'react-select' import StyledSelectField, { StyledMessages } from './style' const SelectField = props =&...

I am trying to integrate react-select using redux form... Here is my code import Select from 'react-select' import StyledSelectField, { StyledMessages } from './style' const SelectField = props =&...