【发布时间】:2022-12-06 07:33:45
【问题描述】:
编码后,我得到一个空白屏幕作为输出。删除该 usestate 函数后,错误已修复,但我需要设置一个健全的后端来反应网站。为此,我需要使用那个 useState 并使用效果挂钩
import React, { useState, useEffect } from "react";
import { motion } from "framer-motion";
import "./About.scss";
import { urlFor, client } from "../../client";
const About = () => {
const [abouts, setAbouts] = useState([]);
useEffect(() => {
const query = '*[_type == "abouts"]';
client.fetch(query).then((data) => {
setAbouts(data);
});
}, []);
return (
<>
<h2 className='head-text'>
I Know that <span>Good Design</span> <br />
means <span>Good Business</span>
</h2>
<div className='app__profiles'>
{abouts.map((about, index) => (
<motion.div
whileInView={{ opacity: 1 }}
whileHover={{ scale: 1.1 }}
transition={{ duration: 0.5, type: "tween" }}
className='app__profile-item'
key={about.title + index}
>
<img src={urlFor(about.imgUrl)} alt={about.title} />
<h2 className='bold-text' style={{ marginTop: 20 }}>
{about.title}
</h2>
<p className='p-text' style={{ marginTop: 10 }}>
{about.description}
</p>
</motion.div>
))}
</div>
</>
);
};
export default About;
【问题讨论】:
-
检查你的浏览器控制台,应该有一个错误。检查并更新问题。
-
你能分享浏览器控制台的截图吗?
标签: reactjs react-hooks