reactjs – ES LINT Warning:- Function declared in a loop contains unsafe references to variable(s) ‘randomColor’, how do I remove this warning?

    //pick random color from existing palettes
    const allColors = this.props.palettes.map(p => p.colors).flat();
    let rand;
    let randomColor = "";
    let isDuplicateColor = true;
    while (isDuplicateColor) {
      rand = Math.floor(Math.random() * allColors.length);
      randomColor = allColors(rand);
      isDuplicateColor = this.state.colors.some(
        color => color.name === randomColor.name
      );
    }
    this.setState({ colors: (...this.state.colors, randomColor) });
  }

this part of the code is giving me the warning “Function declared in a loop contains unsafe references to variable(s) ‘randomColor'” which I have to resolve inorder to deploy