Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site renders just for a few seconds after adding useEffect Hook and fetching data from sanity. #27

Open
nan0hard opened this issue Jun 26, 2022 · 2 comments

Comments

@nan0hard
Copy link

import React, { useEffect, useState } from "react";
import { motion } from "framer-motion";

import { urlFor, client } from "../../client";

import "./About.scss";

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 Devlopment</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;

I think the problem occurred when I added about in About Schema.

@nan0hard
Copy link
Author

Okay, I noticed something whenever I add more than one about the page starts acting weird i.e it shows the entire content for a few milliseconds, and after I remove them and keep just one about an item then the content on the page displays as usual.
I think it has to do something with the useEffect Hook.

@YasirBajwa
Copy link

Hi @nan0hard I did not completely understand what I understand is you are seeing some delay in cards while fetching from sanity it's a normal case in my point of view. You can remove the animation to test it because you have also added a 0.5-sec delay in framer motion div.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants