Git Product home page Git Product logo

Comments (4)

Soso966 avatar Soso966 commented on June 11, 2024

I think I have fixed the error when Using useState and useEffect hooks in reactjs.

from react-use-cart.

notrab avatar notrab commented on June 11, 2024

Hey @Soso966 there's another issue closed with some solutions to get around this with Next.js

#113

Happy to accept a PR if you have a solution that works for everyone.

from react-use-cart.

Soso966 avatar Soso966 commented on June 11, 2024

Hey @Soso966 there's another issue closed with some solutions to get around this with Next.js

#113

Happy to accept a PR if you have a solution that works for everyone.

I am planning to create a hook called useCartItem and this will compose using useState and useEffect instead of implementing them on each page.

from react-use-cart.

iamvinny avatar iamvinny commented on June 11, 2024

I managed to fix this issue by doing like the example below:

"use client";

import CartAdd from "./add-items"; // component
import CartContent from "./content"; // component
import { CartProvider } from "react-use-cart"; // lib
import { useEffect, useState } from 'react'; // lib

export default function CartPage() {
    const [isClient, setIsClient] = useState(false);

    useEffect(() => {
        // This will be executed only on the client side after the initial render
        setIsClient(true);
    }, []);

    // Render nothing on server-side
    if (!isClient) {
        return null;
    }

    return (
        <CartProvider>
            <CartContent />
            <CartAdd />
        </CartProvider>
    );

}

from react-use-cart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.