reactjs - React-typescript och rendering av en array av komponenter


Hej, hur kan jag lösa detta problem? Jag har en array med komponenter men jag kan inte använda typen "any". Så vilken typ har komponenten och hur kan jag övervinna detta fel?

Variable 'stars' implicitly has type 'any[]' in some locations where its type cannot be determined.
Variable 'stars' implicitly has an 'any[]' type.

import { StarIcon } from "@chakra-ui/icons";

interface recipeDesc {
  recipe: Recipe;
}

const stars = [];
const NUMBER_OF_STARS = 5;
let starLimit = 0;

while (starLimit > NUMBER_OF_STARS) {
  starLimit++;
  stars.push(<StarIcon />);
}

const RecipeDescription: React.FC<recipeDesc> = (props) => {
  return (
    <Box marginLeft="2rem">
      <Text fontSize="4rem" fontWeight="700">
        {props.recipe.title}
      </Text>
      {stars}
    </Box>
  );
};

export default RecipeDescription;

Svar #1

const stars: React.ReactElement[] = [];

Relaterade artiklar