【问题标题】:I got a blank screen after coding this section in my react app在我的反应应用程序中编码此部分后,我得到一个空白屏幕
【发布时间】: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


【解决方案1】:

检查 about.title 和 about.imgurl 是否与健全后端相同

【讨论】:

    猜你喜欢
    • 2019-04-27
    • 2022-06-29
    • 2020-11-17
    • 2022-11-13
    • 2019-05-01
    • 2021-09-27
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    相关资源
    最近更新 更多