tailwind css sidebar is not fixed - reactjs

I want to know how to make this sidebar fixed but I don't want to make the navbar and the content below it fixed.
And how I make this responsive means I want to add a hamburger icon to make it responsive on mobile screen devices.
Please help me.
I removed all the SVG icons due to the word limit.
This is the whole code.
// library components
import React from 'react'
import { Link, NavLink } from 'react-router-dom'
const Sidebar = () => {
return (
<div className="relative flex flex-no-wrap">
{/* Sidebar starts */}
{/* Remove class [ hidden ] and replace [ sm:block ] with [ block ] */}
<div className="w-64 absolute sm:relative bg-gray-800 shadow md:h-screen flex-col justify-between hidden sm:flex pb-12">
<div className="px-8">
<div className="h-16 w-full flex items-center">
<h1>Brand Name</h1>
</div>
<ul className="mt-12">
<li className="flex w-full justify-between text-gray-300 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Dashboard</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Products</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Deliverables</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Invoices</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Inventory</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">Settings</span>
</div>
</li>
</ul>
</div>
</div>
{/*Mobile responsive sidebar*/}
<div className="w-64 z-20 absolute bg-gray-800 shadow md:h-full flex-col justify-between sm:hidden pb-12 transition duration-150 ease-in-out" id="mobile-nav">
<div className="h-10 w-10 bg-gray-800 absolute right-0 mt-16 -mr-10 flex items-center shadow rounded-tr rounded-br justify-center cursor-pointer" id="mobile-toggler" onclick="sidebarHandler()">
</div>
<div className="px-8">
<div className="h-16 w-full flex items-center">
</div>
<ul className="mt-12">
<li className="flex w-full justify-between text-gray-300 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Dashboard</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Products</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Performance</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Deliverables</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Invoices</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Inventory</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">Settings</span>
</div>
</li>
</ul>
</div>
</div>
{/* Sidebar ends */}
<div className="w-full">
{/* Navigation starts */}
<nav className="h-16 flex items-center lg:items-stretch justify-end lg:justify-between bg-white shadow relative z-10">
<div className="hidden lg:flex w-full pr-6">
<div className="w-1/2 h-full hidden lg:flex items-center pl-6 pr-24">
<div className="relative w-full">
<div className="text-gray-500 absolute ml-4 inset-0 m-auto w-4 h-4">
</div>
<input className="border border-gray-100 focus:outline-none focus:border-indigo-700 rounded w-full text-sm text-gray-500 bg-gray-100 pl-12 py-2" type="text" placeholder="Search" />
</div>
</div>
<div className="w-1/2 hidden lg:flex">
<div className="w-full flex items-center pl-8 justify-end">
<div className="h-full w-20 flex items-center justify-center border-r border-l">
<div className="relative cursor-pointer text-gray-600">
<div className="w-2 h-2 rounded-full bg-red-400 border border-white absolute inset-0 mt-1 mr-1 m-auto" />
</div>
</div>
<div className="h-full w-20 flex items-center justify-center border-r mr-4 cursor-pointer text-gray-600">
</div>
<div className="flex items-center relative cursor-pointer" onclick="dropdownHandler(this)">
<div className="rounded-full">
<ul className="p-2 w-full border-r bg-white absolute rounded left-0 shadow mt-12 sm:mt-16 hidden">
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">My Profile</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center mt-2">
<div className="flex items-center">
<span className="text-sm ml-2">Sign out</span>
</div>
</li>
</ul>
<div className="relative">
<img className="rounded-full h-10 w-10 object-cover" src="https://tuk-cdn.s3.amazonaws.com/assets/components/sidebar_layout/sl_1.png" alt="avatar" />
<div className="w-2 h-2 rounded-full bg-green-400 border border-white absolute inset-0 mb-0 mr-0 m-auto" />
</div>
</div>
<p className="text-gray-800 text-sm mx-3">Jane Doe</p>
<div className="cursor-pointer text-gray-600">
</div>
</div>
</div>
</div>
</div>
<div className="text-gray-600 mr-8 visible lg:hidden relative" onclick="dropdownHandler(this)">
<ul className="p-2 w-40 border-r bg-white absolute rounded right-0 shadow mt-12 hidden">
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">My Profile</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center mt-2">
<div className="flex items-center">
<span className="text-sm ml-2">Sign out</span>
</div>
</li>
</ul>
</div>
</nav>
{/* Navigation ends */}
{/* Remove class [ h-64 ] when adding a card block */}
<div className="container mx-auto py-10 h-64 md:w-4/5 w-11/12 px-6">
{/* Remove class [ border-dashed border-2 border-gray-300 ] to remove dotted border */}
<div className="w-full h-full rounded border-dashed border-2 border-gray-300">{/* Place your content here */}</div>
</div>
</div>
</div>
);
}
export default Sidebar

Related

Responsive Media React Tailwind

So i have component that i try to make it responsive, but when it comes to media below md: it not working at all and i have some problem on turning the view into what i want
Here is the look on the web view:
and here is the problem :
is that posible to make the button into this when it comes to phone view?
Here is my try:
const CardCalculation = () => {
return (
<div className="ml-2">
<div className="mx-auto lg:flex lg:items-center lg:justify-between">
<h2 className="tracking-tight text-gray-900 sm:text-xl">
<div className="gap-2">
<div className="w-[120px] h-[110px] absolute bg-[#d9d9d9] lg:mb-10"></div>
<div className="text-xl ml-32 text-left text-[#e44]">
Mie Goleng
</div>
<div className="ml-32 text-left text-[#b4b4b4]">Plant K103.</div>
<div className="ml-32 text-left text-[#b4b4b4]">500.02 UOG.</div>
</div>
</h2>
<div className="mt-4 flex lg:mt-0 lg:flex-shrink-0 md:mt-4 sm:mt-8">
<div>
<div className="rounded-md mb-2 shadow">
<a
href="#"
className="inline-flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-5 py-3 text-base font-medium text-white hover:bg-indigo-700"
>
Get started
</a>
</div>
<div className="rounded-md shadow">
<a
href="#"
className="inline-flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-5 py-3 text-base font-medium text-indigo-600 hover:bg-indigo-50"
>
Learn more
</a>
</div>
</div>
</div>
</div>
</div>
);
};
export default CardCalculation;
can someone explained to me why it not responsive to the screen and does it possible to turn the button into horizontal when it comes to phone view as below?
Use the following code:
<div class="p-2">
<div class="flex flex-col md:flex-row md:justify-between">
<div class="flex gap-4">
<div name="grey window" class="h-[110px] w-[120px] bg-[#d9d9d9]"></div>
<div name="text" class="pt-2 md:flex md:flex-col md:justify-evenly md:pt-4">
<div class="text-xl text-[#e44] md:text-3xl">Mie Goleng</div>
<div class="mt-2 text-[#b4b4b4] md:text-xl">Plant K103.</div>
<div class="mt-2 text-[#b4b4b4] md:text-xl">500.02 UOG.</div>
</div>
</div>
<div name="Buttons">
<div class="flex gap-4 md:flex-col p-4 md:p-0">
<div class="rounded-md shadow">
Get started
</div>
<div class="rounded-md shadow">
Learn more
</div>
</div>
</div>
</div>
</div>
Output on large devices:
Output on small devices:
Tailwind play

How do I dynamically change the position of an element in react (tailwind)?

I have a project on react . In it I make a card, when you hover over it, information about this card should appear next to it. Here is the code:
export const CourseCard: React.FC<CourseCardProps> = () => {
const [isShown, setIsShown] = useState(false)
const [xInfoPos, setXInfoPos] = useState("0")
const [yInfoPos, setYInfoPos] = useState("0")
const cardRef = useRef<HTMLDivElement>(null)
const infoCardRef = useRef<HTMLDivElement>(null)
const formateXCord = (x : Number | undefined) => {
return "left-[" + x + "px]"
}
const formateYCord = (y : Number | undefined ) => {
return "top-[" + y + "px]"
}
const carMouseHandler = () => {
const cardEl = cardRef.current?.getBoundingClientRect()
const infoCardEl = infoCardRef.current?.getBoundingClientRect()
setXInfoPos(formateXCord(cardEl?.right))
setYInfoPos(formateYCord(cardEl?.top))
setIsShown(true)
}
return (
<>
<div ref={cardRef} onMouseEnter={carMouseHandler} onMouseLeave={()=>setIsShown(false)} className="py-0 px-4 relative snap-center flex flex-col w-1/4">
<div className="relative rounded-t-xl rounded-b-none bg-white shrink-0">
<img className="block w-full h-auto rounded-t rounded-b-none" src={cardImage} />
<button className="absolute top-2.5 right-2.5 h-6 w-6 rounded-full bg-gray-700 text-white font-bold text-center">♡</button>
</div>
<div className="py-2.5 px-3.5 bg-white border-[1px] border-solid border-gray-300 rounded-b border-t-0 flex-1 flex flex-col">
<div className="mb-2 flex flex-wrap items-center">
<span className="text-lg leading-4 text-cyan-600 mr-2"></span>
<span className="text-sm leading-4 text-blue-400 line-through"></span>
</div>
<h3 className="text-lg leading-4 mb-2 text-black font-normal h-14 overflow-hidden">TITLE</h3>
<div className="text-sm leading-5 opacity-40 mt-auto">Teacher Name</div>
</div>
{isShown &&
<div ref={infoCardRef} className={`flex flex-col absolute ${xInfoPos} ${yInfoPos} z-20 rounded-t-md w-full py-4 px-4 bg-slate-100`} >
<div className="mb-2 text-sm leading-5 text-black flex items-center">
<img className="block rounded-full w-7 h-7 shrink-0 mr-2" src={cardImage} />
Autor
</div>
<div className="text-lg leading-5 font-light text-black mb-2">
Title
</div>
<ul className="list-none p-0 mb-2 w-full block">
<li className="top-0 left-0 bg-white w-full" >
<img className="block w-full rounded-md top-0 left-0 right-0 bottom-0 h-full object-cover" src={cardImage}></img>
</li>
</ul>
<div className="text-sm leading-5 text-black mb-2">
Description
</div>
<ul className="-mx-2 list-none p-0 flex flex-wrap">
<li className="w-1/2 mb-2.5 text-sm leading-5 text-gray-800 flex items-center">
<img className="block shrink-0 mr-2.5"></img>
file
</li>
<li className="px-2.5 w-1/2 mb-2.5 text-sm leading-5 text-gray-800 flex items-center">
<img className="block shrink-0 mr-2.5"></img>
clock
</li>
<li className="w-1/2 mb-2.5 text-sm leading-5 text-gray-800 flex items-center">
<img className="block shrink-0 mr-2.5"></img>
books
</li>
<li className="px-2.5 w-1/2 mb-2.5 text-sm leading-5 text-gray-800 flex items-center">
<img className="block shrink-0 mr-2.5"></img>
lang
</li>
</ul>
<div className="pt-2 text-base leading-5 font-light text-gray-800 border-t border-solid border-t-black">footer</div>
</div>
}
</div>
</>
);
};
But I ran into a problem , the project uses tailwind and the concatenation doesn't work with it
"left-[" + x + "px]"
I found an article describing it https://v2.tailwindcss.com/docs/just-in-time-mode
but if I write like this
"left-[400px]"
it works.
The solution suggested in this article does not work because there can be many variants of x and y.
Right now the information is blocking the card which the cursor is pointing at.
Can you tell me how to solve this problem or give me another way to solve it?
Note: Information about the card should appear depending on the location of the card itself. If the card is located at the bottom then the information appears above it, if it is at the top then the information appears below it. Otherwise, on the right or left of the card.
My answer has two part.
Part one: tailwind generate style when you use and if you want to use dynamically you mist have confidence that style exist and you can generate all dynamic style one by one like this
"left-[400px]"
And part two: you have to use your classname like below
className={`left-[${x}px]`}

TypeError: items.map is not a function

My code problem is that I want to create a token from the backend and add it to my item. Now the page is crashing due to mapping the data.
<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items?.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>
try to change it this way
<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items && items.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>

Can't find missing key in 'Each child in a list should have a unique "key" prop'

I've been starring at my code, but I can't see where the key is missing. That is my error:
Warning: Each child in a list should have a unique "key" prop.
Check the render method of Card. It was passed a child from ContractInfo.
Here is Card:
export const Card = ({ selected, onChange, title, price, frequency, description, feature, cta }) => {
const mode = selected ? 'border-yellow-500 border-4' : 'border-gray-200'
return (
<div
className={["relative p-8 bg-white border-gray-200 rounded-2xl shadow-sm flex flex-col border-2", mode].join(' ')}
style={{cursor:'pointer'}}
selected={selected}
onClick={onChange}
>
<div className="flex-1 ">
<h3 className="text-xl font-semibold text-gray-900">{title}</h3>
<p className="mt-4 flex items-baseline text-gray-900">
<span className="text-5xl font-extrabold tracking-tight">€{price}</span>
<span className="ml-1 text-xl font-semibold">{frequency}</span>
</p>
<p className="mt-6 text-gray-500">{description}</p>
{/* Feature list */}
{feature}
</div>
<div className= 'bg-yellow-500 text-white hover:bg-yellow-600 mt-8 block w-full py-3 px-6 border border-transparent rounded-md text-center font-medium'>
{cta}
</div>
</div>
);
}
And here is the bit in ContractInfo:
return (
<div className={formStep === 0 ? 'block' : 'hidden'}>
<div className="bg-white py-16 px-4 overflow-hidden sm:px-6 lg:px-8">
<div className="relative max-w-xl mx-auto">
<div className="text-center">
<h2 className="text-3xl font-extrabold tracking-tight text-gray-600 sm:text-4xl">Welcher Vertrag passt zu dir?</h2>
</div>
</div>
<div className="max-w-7xl mx-auto py-4 px-4 bg-white sm:px-6 lg:px-8">
<div className="mt space-y-12 lg:space-y-0 lg:grid lg:grid-cols-3 lg:gap-x-8">
{contracts.map((contract, index) => (
<Card
key={contract.id}
title={contract.title}
price={contract.price}
frequency={contract.frequency}
description={contract.description}
feature={ contract.features.map((feature, index) =>
<ul role="list" className="mt-6 space-y-6">
<li className="flex" key={feature.id} >
{console.log(feature.id)}
<CheckIcon className="flex-shrink-0 w-6 h-6 text-yellow-500" aria-hidden="true" />
{feature.name}
</li>
</ul> )}
cta={contract.cta}
selected={isSelected === index}
onChange={() => setisSelected(index)}
/>
))}
{/* {console.log(contracts?.[isSelected])} */}
</div>
</div>
<div className="mt-5 sm:mt-8 sm:flex sm:justify-center lg:justify-center">
<div className="rounded-md shadow">
<a role="button" tabIndex={0}
className="w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-gray-200 hover:bg-gray-200 focus:outline-none md:py-4 md:text-lg md:px-10 cursor-not-allowed"
>
Zurück
</a>
</div>
<div className="mt-3 sm:mt-0 sm:ml-3">
<a
//onClick={nextQuizStep}
onClick={() => nextFormStep(contracts?.[isSelected]) }
className="w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-yellow-500 hover:bg-yallow-600 md:py-4 md:text-lg md:px-10"
>
Weiter
</a>
</div>
</div>
</div>
</div>
);
}
Keys are both present for features list and for cards. Where is the problem?
Key Error is caused by feature rendering in Card component
This is cause the keys are not present among sibling elements of the for loop in feature creation, so to correct this You set key for parent ul in
feature={ contract.features.map((feature, index) =>
<ul role="list" className="mt-6 space-y-6">
<li className="flex" key={feature.id} >
{console.log(feature.id)}
<CheckIcon className="flex-shrink-0 w-6 h-6 text-yellow-500" aria-hidden="true" />
{feature.name}
</li>
</ul> )}
so it becomes
feature={ contract.features.map((feature, index) =>
<ul role="list" className="mt-6 space-y-6" key={'feature-'+feature.id}>
<li className="flex" >
{console.log(feature.id)}
<CheckIcon className="flex-shrink-0 w-6 h-6 text-yellow-500" aria-hidden="true" />
{feature.name}
</li>
</ul> )}

NextJS, it doesn't display on the web but if the data is displayed in console.log

I have a problem where I use getInitialProps to fetch data but I show on the web it doesn't appear but if my data is try console.log the data will appear accordingly
{this.props.siswa.map(siswa => {
{console.log(siswa)}
<div className="flex">
<div className="py-8 px-8 w-full lg:max-w-sm bg-white rounded-xl shadow-md hover:shadow-xl space-y-2 sm:py-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-6 dark:bg-indigo-600 ml-0 lg:ml-3 sm:mt-2 md:w-full">
<img className="block mx-auto object-cover w-24 h-24 rounded-full sm:mx-0 sm:flex-shrink-0" src={`/img/siswa/${siswa.id}.jpg`} loading="lazy" />
<div className="text-center space-y-2 sm:text-left">
<div className="space-y-0.5">
<p className="text-lg text-black font-semibold dark:text-gray-200">
{siswa.panggilan}
</p>
<p className="text-gray-500 font-medium dark:text-gray-300">
{siswa.nama}
</p>
</div>
<button id="om" className="px-4 py-1 text-sm text-indigo-600 font-semibold rounded-full border border-indigo-400 hover:text-white hover:bg-indigo-600 hover:border-transparent focus:outline-none focus:ring-1 focus:ring-indigo-600 focus:ring-offset-2 dark:text-gray-200 dark:border-white dark:hover:text-gray-200 dark:hover:border-indigo-800 dark:hover:bg-indigo-800 dark:focus:ring-indigo-800 w-full md:w-2/4" onClick={() => this.setState({showModalSiswa: true})}>Detail</button>
</div>
</div>
</div>
})}
this is the data that comes up if I do console.log
{
id: '1',
nama: 'Ipsun',
panggilan: 'ipsun',
ttl: 'ipsun',
alamat: 'ipsun',
nope: '43143',
ig: '#ipsun',
line: null,
telegram: null,
tiktok: null,
fb: null,
linkedin: null,
pesan: 'ipsun'
}
{
id: '2',
nama: 'lorem',
panggilan: 'lorem',
ttl: 'lorem',
alamat: 'lorem',
nope: '41413',
ig: '#lorem',
line: null,
telegram: null,
tiktok: null,
fb: null,
linkedin: null,
pesan: 'lorem'
}
It's because you're not returning any jsx from your .map ;)
{this.props.siswa.map(siswa => {
{console.log(siswa)}
return (
<div className="flex">
<div className="py-8 px-8 w-full lg:max-w-sm bg-white rounded-xl shadow-md hover:shadow-xl space-y-2 sm:py-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-6 dark:bg-indigo-600 ml-0 lg:ml-3 sm:mt-2 md:w-full">
<img className="block mx-auto object-cover w-24 h-24 rounded-full sm:mx-0 sm:flex-shrink-0" src={`/img/siswa/${siswa.id}.jpg`} loading="lazy" />
<div className="text-center space-y-2 sm:text-left">
<div className="space-y-0.5">
<p className="text-lg text-black font-semibold dark:text-gray-200">
{siswa.panggilan}
</p>
<p className="text-gray-500 font-medium dark:text-gray-300">
{siswa.nama}
</p>
</div>
<button id="om" className="px-4 py-1 text-sm text-indigo-600 font-semibold rounded-full border border-indigo-400 hover:text-white hover:bg-indigo-600 hover:border-transparent focus:outline-none focus:ring-1 focus:ring-indigo-600 focus:ring-offset-2 dark:text-gray-200 dark:border-white dark:hover:text-gray-200 dark:hover:border-indigo-800 dark:hover:bg-indigo-800 dark:focus:ring-indigo-800 w-full md:w-2/4" onClick={() => this.setState({showModalSiswa: true})}>Detail</button>
</div>
</div>
</div>
)
})}
Or you can return like this:
{this.props.siswa.map(siswa =>
<div className="flex">
<div className="py-8 px-8 w-full lg:max-w-sm bg-white rounded-xl shadow-md hover:shadow-xl space-y-2 sm:py-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-6 dark:bg-indigo-600 ml-0 lg:ml-3 sm:mt-2 md:w-full">
<img className="block mx-auto object-cover w-24 h-24 rounded-full sm:mx-0 sm:flex-shrink-0" src={`/img/siswa/${siswa.id}.jpg`} loading="lazy" />
<div className="text-center space-y-2 sm:text-left">
<div className="space-y-0.5">
<p className="text-lg text-black font-semibold dark:text-gray-200">
{siswa.panggilan}
</p>
<p className="text-gray-500 font-medium dark:text-gray-300">
{siswa.nama}
</p>
</div>
<button id="om" className="px-4 py-1 text-sm text-indigo-600 font-semibold rounded-full border border-indigo-400 hover:text-white hover:bg-indigo-600 hover:border-transparent focus:outline-none focus:ring-1 focus:ring-indigo-600 focus:ring-offset-2 dark:text-gray-200 dark:border-white dark:hover:text-gray-200 dark:hover:border-indigo-800 dark:hover:bg-indigo-800 dark:focus:ring-indigo-800 w-full md:w-2/4" onClick={() => this.setState({showModalSiswa: true})}>Detail</button>
</div>
</div>
</div>
}
Alternatively, you can omit the return keyword by using an implicit return:
const ComponentTest = ({ siswa }) =>
siswa.map((siswa) => (
<div className="flex">
{console.log(siswa)}
<div className="py-8 px-8 w-full lg:max-w-sm bg-white rounded-xl shadow-md hover:shadow-xl space-y-2 sm:py-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-6 dark:bg-indigo-600 ml-0 lg:ml-3 sm:mt-2 md:w-full">
<img
className="block mx-auto object-cover w-24 h-24 rounded-full sm:mx-0 sm:flex-shrink-0"
src={`/img/siswa/${siswa.id}.jpg`}
loading="lazy"
/>
<div className="text-center space-y-2 sm:text-left">
<div className="space-y-0.5">
<p className="text-lg text-black font-semibold dark:text-gray-200">
{siswa.panggilan}
</p>
<p className="text-gray-500 font-medium dark:text-gray-300">
{siswa.nama}
</p>
</div>
<button
id="om"
className="px-4 py-1 text-sm text-indigo-600 font-semibold rounded-full border border-indigo-400 hover:text-white hover:bg-indigo-600 hover:border-transparent focus:outline-none focus:ring-1 focus:ring-indigo-600 focus:ring-offset-2 dark:text-gray-200 dark:border-white dark:hover:text-gray-200 dark:hover:border-indigo-800 dark:hover:bg-indigo-800 dark:focus:ring-indigo-800 w-full md:w-2/4"
onClick={() => this.setState({ showModalSiswa: true })}
>
Detail
</button>
</div>
</div>
</div>
));
Note the console.log is within JSX, this is fine since it is wrapped with curly brackets and gets evaluated.

Resources