javascript - 如何让卡片一张张出现?
问题描述
我有这个代码:
import React, { useState } from 'react';
import PropTypes from "prop-types";
import { Div, Panel, Button, PanelHeader } from "@vkontakte/vkui"
import TinderCard from 'react-tinder-card'
const Home = ({ id, go, sortUsersData }) => {
const dataArray = sortUsersData;
const [lastDirection, setLastDirection] = useState()
const swiped = (direction, nameToDelete) => {
console.log('removing: ' + nameToDelete)
setLastDirection(direction)
}
const outOfFrame = (name) => {
console.log(name + ' left the screen!');
}
return (
<Panel id={id}>
<PanelHeader>Title</PanelHeader>
<Div>
<div className='cardContainer'>
{
dataArray.map((character) =>
<TinderCard className="swipe" key={character.first_name} onSwipe={(dir) => swiped(dir, character.first_name)} onCardLeftScreen={() => outOfFrame(character.name)} preventSwipe={["up", "down"]}>
<div style={{ backgroundImage: "url(" + character.image + ")" }} className="card">
<h3 class="name">{character.first_name}</h3>
<h2 class="age">{character.distance} лет</h2>
<h1 class="bio">{character.bio}</h1>
</div>
</TinderCard>
)
}
</div>
{lastDirection ? <h2 className="infoText">You swiped {lastDirection}</h2> : <h2 className="infoText"/>}
</Div>
</Panel>
);
};
export default Home;
当我运行它时,我看到了所有的卡片,但我想知道如何让它们按顺序出现。当我从屏幕上刷一张卡时,会加载另一张卡。我想这样做是因为当我有一个非常大的阵列时,它开始工作得非常缓慢。
谢谢!!
解决方案
推荐阅读
- sql - CONCAT后如何在重复行号上拆分字符串
- git - Github“嵌套”存储库,但不是子模块
- android - 如何制作这个 OTPView ?我想通过布局按钮而不是 Xamain.Android 中的软键盘提供输入
- postgresql - PostgreSQL 拒绝连接
- javascript - Google 应用程序脚本 - 内置依赖项验证
- powershell - $obj.psObject.properties[$key].value 可以缩写吗
- ruby-on-rails - NameError:未初始化的常量应该
- javascript - 获取最高属性的ID
- asp.net-mvc - 如何在 MVC 中从数据库中填充 DropDownList
- c - 我想将变量类型放在字符串中的某个位置