您好,我有一个问题如何在顺风网格中使用重复和最小最大。我做了类似的事情,但没有成功。
const DetailedAssetCard = () => {
return (
<div className=" bg-gray-100 rounded-lg grid grid-cols-[repeat(4, minmax(100px, 500px))] ">
<div className="w-32 h-32 rounded-full ">
<Image src={Btc} alt="" />
</div>
<p>
Hello <span className="block ">123</span>
</p>
<p>
Hello <span className="block ">123</span>
</p>
<p>
Hello <span className="block ">123</span>
</p>
<p>
Hello <span className="block ">123</span>
</p>
<p>
Hello <span className="block ">123</span>
</p>
<p>
Hello <span className="block ">123</span>
</p>
</div>
);
};
Run Code Online (Sandbox Code Playgroud) 您好,我该如何解决这个问题?我有一系列组件,但不能使用“任何”类型。那么什么类型的组件有什么类型以及如何克服这个错误?
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;
Run Code Online (Sandbox Code Playgroud) 您好,如何在注册 Firebase 用户时设置用户名。我使用 firebase 身份验证 API。我考虑过 try / catch 块并设置用户属性,例如
const user = auth.currentUser;
user.name = 'John123'
Run Code Online (Sandbox Code Playgroud)
是否可以?
const onSubmitHandler = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
createUserWithEmailAndPassword(auth, email, password)
}
Run Code Online (Sandbox Code Playgroud) 我有个问题。如何为字符串数组生成密钥?它不是对象,在对象中我可以放置 id ,它可以解决问题。那么我应该在数组中做什么呢?将索引作为键并不是一个好的做法,所以我陷入了困境。
const ingredients = ['rice', 'curry', 'chicken]
{props.ingredients.map((ingredient) => (
<Box>{ingredient}</Box>
))}
Run Code Online (Sandbox Code Playgroud) 你好,我想将 setInterval 放入我的 React 项目中,每秒加 1,但我收到了像本文标题一样的错误。js:
const [activeTab, setActiveTab] = useState(0)
useEffect(() => {
setInterval(setActiveTab(prevTab => {
if (prevTab === 3) return 0
console.log('hi')
return prevTab += 1
}), 1000)
})
Run Code Online (Sandbox Code Playgroud) 如何将 ref 属性推送到子组件?我收到错误:
'{ reference: RefObject<HTMLSelectElement>; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'.
Property 'reference' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'.
Run Code Online (Sandbox Code Playgroud)
我知道它与 React.FC<> 和通用函数有关,但我不知道它是什么类型,我应该在 <> 之间写什么来处理从另一个组件推送的引用。
*编辑:我知道我可以使用forwardRef,但这个问题的重点是如何使用 props 传递 ref。
const typeRef = useRef<HTMLSelectElement>(null)
const descriptionRef = useRef<HTMLTextAreaElement>(null)
const onSubmitHandler = (e: React.FormEvent): void => {
e.preventDefault()
}
return (
<React.Fragment>
<Navbar />
<Center width="100%" height="95vh">
<Flex justifyContent="center" alignItems="center" width="50vw">
<FormControl textAlign="center" onSubmit={onSubmitHandler}>
<Input ref={titleRef} placeholder="Name for your recipe" /> …Run Code Online (Sandbox Code Playgroud)