import React from 'react'
import net from '../assets/netflix.png'
const Porfolio = () => {
const Projects = [
{
id:1,
title:"Netflix Clone",
desc:"Netflix Landing Page Clone using React JS and Tailwind CSS with Authentication Feature using Firebase",
imgLink:net,
codeLink:"https://github.com/codegoggins/netflix-clone",
projectLink:"https://netflix-clone-13127.firebaseapp.com/"
}
]
return (
<div
className='px-20 py-4'>
<p
className='text-white text-4xl'
>Projects</p>
{/* PROJECT CARDS */}
<div
className='mt-8 flex flex-col justify-center items-center md:flex md:items-start'
>
{
Projects.map(({id,title,desc,imgLink,codeLink,projectLink})=>(
<>
{/* SINGLE CARD */}
<div className='w-[340px] h-auto relative group md:w-[500px]'>
{/* OVERLAY */}
<div
className='bg-black/80 text-sm md:text-lg absolute flex top-0 bottom-0 h-full w-full rounded-lg overflow-hidden opacity-0 group-hover:opacity-100 transition-all duration-300'>
{/* PROJECT DETAILS */}
<div
className='text-white text-sm md:text-lg flex flex-col p-4 gap-3 md:gap-2 items-center justify-center'>
{/* TITLE */}
<p>{title}</p>
{/* DETAIL */}
<p>{desc}</p>
{/* BUTTONS */}
<div
className='flex gap-3 text-sm md:text-lg'>
<button
className='cursor-pointer font-semibold p-1.5 px-4 rounded-md bg-white text-black transition ease-linear duration-300'
>
Code
</button>
<button
className='cursor-pointer font-semibold p-1.5 px-2 rounded-md bg-white text-black transition ease-linear duration-300'>
See Project
</button>
</div>
</div>
</div>
{/* Image */}
<div className='rounded-lg overflow-hidden'>
<img src={imgLink} alt="" className='h-full w-full object-cover'/>
</div>
</div>
</>
))
}
</div>
</div>
)
}
export default Porfolio
I am getting error to add key , for that instead of react fragments, I
replace it with a div and give key to it but I am getting error. With
react fragments I don't get any error but I can't add key to it for
mapping.
I want the card details to be mapped on all the cards.
enter image description here
You should return inside mapping and provide a key for the root element.
for example,
{
products?.map(({ id, title, desc, imgLink, codeLink, projectLink }) => {
return (
<div key={id} className='w-[340px] h-auto relative group md:w-[500px]'>
//Your code here
</div>
)
})}
You can add:
<React.Fragment key={id}>
some code
</React.Fragment>
or remove the fragment and add the key to the first div inside the map
Related
I have the following page with three tabs("Info", "Rules", and "Wiki"):
import React, { useState, useEffect } from 'react';
import { Navbar } from '../components';
function Information() {
const [selectedTab, setSelectedTab] = useState('instrucciones');
return (
<>
<Navbar>Información y normativa</Navbar>
<div className="relative pt-16 pb-16 min-h-screen w-screen bg-gray-200">
<div className="w-full overflow-visible ">
<div className="flex overflow-x-scroll no-scrollbar max-w-full mt-4 ml-4 whitespace-nowrap">
<button
onClick={() => setSelectedTab('instrucciones')}
className={`flex-1 py-2 px-4 text-center text-black bg-white rounded-full ${
selectedTab === 'instrucciones'
? 'bg-primary font-bold active'
: 'hover:border-stone-400'
} mr-4`}
>
Instrucciones
</button>
<button
onClick={() => setSelectedTab('normativa')}
className={`flex-1 py-2 px-4 text-center text-black bg-white rounded-full ${
selectedTab === 'normativa'
? 'bg-primary font-bold active'
: 'hover:border-stone-400'
} mr-4`}
>
Normativa
</button>
<button
onClick={() => setSelectedTab('wiki')}
className={`flex-1 py-2 px-4 text-center text-black bg-white rounded-full ${
selectedTab === 'wiki'
? 'bg-primary font-bold active'
: 'hover:border-stone-400'
}`}
>
Wiki
</button>
</div>
{selectedTab === 'instrucciones' && (
<div>
<h1 className="mt-6 ml-3 p-3 text-left text-lg font-bold text-black">
INSTRUCTIONS
</h1>
</div>
)}
{selectedTab === 'normativa' && (
<div>
<h1 className="mt-6 ml-3 p-3 text-left text-lg font-bold text-black">
NORMATIVA
</h1>
</div>
)}
{selectedTab === 'wiki' && (
<div>
<h1 className="mt-6 ml-3 p-3 text-left text-lg font-bold text-black">
WIKI
</h1>
</div>
)}
</div>
</div>
</>
);
}
export default Information;
I´m trying to open it with the tab wiki active when the user clicks on the Information button from the page /wiki (that´s the route), for any other page, it should open with the tab Info. How can I go about it? I´ve tried using useLocation but i received a empty ''.
you recieved empty because you are not using any routing at all, you are using conditional rendering instead, which is wrong. you have to change a lot of things(you have to use things like BrowserRouter, Routes, Route, Link) so I recommend reading docs about routing https://reactrouter.com/en/main/router-components/browser-router
Initially I made a project and there the Navbar was completely ok. But I want to use the same Navbar on similar kind of project. But while type or copy paste the code the design is completely change. Even after a lot of search I can't find the actual problem as well as the solution also.
Both having same CSS file as well. Then where the problem occurs ?? Is there any change happened for Tailwind CSS design ?? Kindly let me know.
Navbar of previous project :
Navbar of present project :
Even though all codes are same. I put all the Navbar code below.
import { HiMenuAlt4 } from 'react-icons/hi';
import { AiOutlineClose } from 'react-icons/ai';
import logo from '../../images/logo.png';
const NavbarItem = ({ title, classProps }) => {
return (
<li className={`mx-4 cursor-pointer ${classProps}`}>
{title}
</li>
)
}
const Navbar = () => {
const [toggleMenu, setToggleMenu] = useState(false); //Mobile View On or Not
return (
<nav className="w-full flex md:justify-center justify-between items-center p-4">
<div className="md:flex-[0.5] flex-initial justify-center items-center">
<img src={logo} alt="logo" className="w-32 cursor-pointer"/>
</div>
<ul className="text-white md:flex hidden list-none flex-row justify-between items-center flex-initial">
{["Buy","Sell","Transfer","Wallets","About Us"].map((item, index) => (
<NavbarItem key={item + index} title={item} />
))}
<li className="bg-[#3d4f79] py-2 px-7 mx-4 rounded-full cursor-pointer hover:bg-[#2546]">
SIGN IN
</li>
</ul>
{/* Mobile View */}
<div className="flex relative">
{toggleMenu
? <AiOutlineClose fontSize={28} className="text-white md:hidden cursor-pointer" onClick={() => setToggleMenu(false)} />
: <HiMenuAlt4 fontSize={28} className="text-white md:hidden cursor-pointer" onClick={() => setToggleMenu(true)} />
}
{toggleMenu && (
<ul
className="z-10 fixed top-0 -right-2 p-3 w-[70vw] h-screen shadow-2x1 md:hidden list-none
flex flex-col justify-start items-end rounded-md blue-glassmorphism text-white animate-slide-in"
>
<li className="text-xl w-full my-2">
<AiOutlineClose onClick={() => setToggleMenu(false)} />
</li>
{["Market","Exchange","Tutorials","Wallets"].map((item, index) => (
<NavbarItem key={item + index} title={item} classProps="my-2 text-lg"/>
))}
</ul>
)}
</div>
</nav>
);
}
export default Navbar;```
by adding classname navbar fixed <nav className="fixed w-full flex md:justify-center justify-between items-center p-4">
const StyledInput = styled.input`w-full focus:ring-indigo-500 focus:border-indigo-500 block p-2 border-gray-300 border-2 rounded-md`;
export const Input = (props: StyledInputProps) => {
return props.iconPosition === 'trailing' ? (
<div>
{props.label && <div tw="text-coolGray-800">{props.label}</div>}
<div tw="w-full relative rounded-md shadow-sm flex">
<StyledInput {...props} />
<div tw="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
{props.icon}
</div>
</div>
</div>
) : (
<div>
{props.label && <div tw="text-coolGray-800">{props.label}</div>}
<div tw="w-full relative rounded-md flex bg-white">
{props.icon && (
<div tw="z-10 h-full leading-snug font-normal absolute text-center rounded text-base items-center justify-center w-8 pl-3 py-3">
{props.icon}
</div>
)}
<StyledInput {...props} />
</div>
</div>
);
};
No Matter how I try to style the leading input Icon, I always get this:
I'm trying to get the icon to go inside the input element, like Put icon inside input element in a form
But Even trying all the normal answers, I can't figure it out, is there something really dumb I'm missing?
In my index.tsx I have
<Header/>
In my Header.js component, I am using a HeroIcon embedded component.
export default function Header() {
return (
<header className='flex flex-col sm:flex-row m-5 justify-between items-center h-auto'>
<div className='flex flex-grow justify-evenly max-w-2xl'>
<HeaderItem title='HOME' Icon={HomeIcon} />
<HeaderItem title='ACCOUNT' Icon={UserIcon} />
In my HeaderItem.js
export default function HeaderItem({Icon,title}) {
return (
<div className="flex flex-col items-center cursor-pointer group w-12 sm:w-20
hover:text-red">
<Icon className="h-8 mb-1 group-hover:animate-bounce"/>
<p className="opacity-0 group-hover:opacity-100 tracking-widest"> {title} </p>
</div>
)
}
As far as I understand, I can pass a ref from the Header to HeaderItem component via props and then use the Link tag.
How do I wrap that around without losing the animation?
OK so this works for me -
On Header.js
<HeaderItem title='HOME' Icon={HomeIcon} url="/"/>
On the HeaderItem.js
export default function HeaderItem({Icon,title, url}) {
return (
<Link href={url}>
<div className="flex flex-col items-center cursor-pointer group w-12 sm:w-20
hover:text-red">
<Icon className="h-8 mb-1 group-hover:animate-bounce"/>
<p className="opacity-0 group-hover:opacity-100 tracking-widest"> {title} </p>
</div>
</Link>
)
}
I am trying to learn react js with tailwindcss but I am getting extra whitespace which is not detecting when I inspect it also in mobile view it occupies half of the screen
import React, { useEffect, useState } from "react";
const Hero = () => {
const [animated, setanimated] = useState(false);
useEffect(() => {
setanimated(true);
}, []);
return (
<div
className="min-h-screen w-screen flex justify-center items-center flex-col-reverse md:flex-row md:justify-around "
style={{
background: "linear-gradient(to bottom, #aaacc0, #F0F4FD)",
}}
>
<div
className={`${
animated ? "scale-y-100" : "scale-y-0"
} mt-4 text-center font-nunito transform transition duration-1000 ease-in-out`}
>
<h1 className="font-bold text-3xl md:text-6xl md:flex-col">
Fresh Delicious
<span className="font-extrabold text-3xl md:text-6xl"> Noodles</span>
</h1>
<p className="text-base mt-5 ">We cook most tasty Noodles in Mumbai</p>
<p className="text-base">
We care for you! We maintain{" "}
<span className="md:text-lg md:font-semibold"> Hygein</span> and{" "}
<span className="md:text-lg md:font-semibold"> Contactless</span>{" "}
delivery!
</p>
<button className="inline-block bg-yellow-400 px-10 py-5 rounded-full mt-10 shadow-lg border-2 text-lg font-semibold text-black uppercase tracking-wide duration-1000 animate-bounce">
Order Now!
</button>
</div>
<img
src={process.env.PUBLIC_URL + "/assets/bowl.svg"}
alt="BOWL"
className={`${
animated ? "scale-90" : "translate-x-full translate-y-full"
} mx-5 my-5 w-auto h-auto md:max-w-xl transform transition duration-1000 ease-in-out `}
/>
</div>
);
};
export default Hero;
you can see website here
my website where I am getting bug
Try adding a class on #root div tag
overflow-x-hidden
or
#root {
#apply overflow-x-hidden;
}
The reason this is happening are the animation's starting point.