skip to Main Content

Warning: React does not recognize the dataSlot prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase dataslot instead. If you accidentally passed it from a parent component, remove it from the DOM element.

import React, { useState } from "react";
import logo from "../assets/images/logo.png";
import { HiMoon, HiSun } from "react-icons/hi2";

function Header() {
    const [isMoon, setIsMoon] = useState(true);

    // Function to toggle between moon and sun
    const toggleTheme = () => {
        setIsMoon((prevIsMoon) => !prevIsMoon);
    };

    return (
        <div className="flex items-center">
            <img src={logo} width={90} height={90} alt="Logo" />
            <div className="flex bg-slate-200 p-2 w-full mx-5 rounded-full items-center">
                <input
                    type="text"
                    placeholder="Search Games"
                    className="bg-transparent outline-none"
                />
            </div>
            <div onClick={toggleTheme}>
                {isMoon ? (
                    <HiMoon className="text-[35px] bg-slate-200 text-black p-1 rounded-full cursor-pointer" />
                ) : (
                    <HiSun className="text-[35px] bg-slate-200 text-black p-1 rounded-full cursor-pointer" />
                )}
            </div>
        </div>
    );
}

export default Header;

2

Answers


  1. Yes, the same thing happens to me but only when using react-icons/hi2, at least using other react-icons icons there is no such problem

    Login or Signup to reply.
  2. This is an issue from react-icons in version 5.1.0+. Reference

    Possible Solutions

    1. Downgrade to a version lower than 5.1.0
    2. Replace icons from the react-icons/hi2 library with other options.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search