当前位置:网站首页>The carousel component of ant design calls prev and next methods in TS (typescript) environment
The carousel component of ant design calls prev and next methods in TS (typescript) environment
2022-07-06 09:03:00 【Frost and snow】
One . Environmental Science
react: “18.1.0”
antd:“^4.20.5” (react edition )
next.js:“12.1.6”
typescript:“4.6.4”
Two . Code
import type {
NextPage, GetServerSideProps, InferGetServerSidePropsType } from 'next'
import styles from '../styles/Home.module.scss'
import cn from 'classnames'
import {
Store } from '@/store/store'
import {
createRef } from 'react'
import {
Carousel, Button } from 'antd'
import type {
CarouselRef } from 'antd/lib/carousel'
interface IProps {
}
const contentStyle: React.CSSProperties = {
height: '160px',
color: '#fff',
lineHeight: '160px',
textAlign: 'center',
background: '#364d79',
}
const Home: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>> = ({
}) => {
const carRef = createRef<CarouselRef>()
const next = () => {
console.log('next')
carRef.current?.next()
}
const prev = () => {
console.log(carRef)
console.log('prev')
carRef.current?.prev()
}
// dots={false} hide tab Toggle bar ( Small button ) vertical={true} Moving vertically
return (
<div className={
cn(styles['home-page'])}>
<Carousel dots={
false} ref={
carRef} vertical={
true}>
<div>
<div style={
contentStyle}>1</div>
</div>
<div>
<div style={
contentStyle}>2</div>
</div>
<div>
<div style={
contentStyle}>3</div>
</div>
<div>
<div style={
contentStyle}>4</div>
</div>
</Carousel>
<Button onClick={
next}>next</Button>
<Button onClick={
prev}>prev</Button>
</div>
)
}
export default Home
export const getServerSideProps: GetServerSideProps<IProps> = Store.getServerSideProps((store) => async ({
req }) => {
return {
props: {
},
}
})
The effect is as follows :

( End )
边栏推荐
- Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
- 甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
- Tdengine biweekly selection of community issues | phase III
- Philosophical enlightenment from single point to distributed
- Leetcode: Jianzhi offer 04 Search in two-dimensional array
- LeetCode:162. Looking for peak
- LeetCode:162. 寻找峰值
- LeetCode:34. Find the first and last positions of elements in a sorted array
- LeetCode:221. Largest Square
- What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
猜你喜欢

数字人主播618手语带货,便捷2780万名听障人士

BN folding and its quantification

UML圖記憶技巧

Promise 在uniapp的简单使用

Different data-driven code executes the same test scenario

LeetCode:221. 最大正方形

如何正确截取字符串(例:应用报错信息截取入库操作)

A convolution substitution of attention mechanism

SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date

Intel distiller Toolkit - Quantitative implementation 3
随机推荐
Problems encountered in connecting the database of the project and their solutions
LeetCode:387. The first unique character in the string
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
自定义卷积注意力算子的CUDA实现
Pytest之收集用例规则与运行指定用例
Esp8266-rtos IOT development
数学建模2004B题(输电问题)
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
【嵌入式】Cortex M4F DSP库
Intel Distiller工具包-量化实现1
LeetCode:162. Looking for peak
Simclr: comparative learning in NLP
CUDA实现focal_loss
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Advance Computer Network Review(1)——FatTree
Leetcode: Jianzhi offer 03 Duplicate numbers in array
Variable length parameter
力扣每日一题(二)
【shell脚本】——归档文件脚本
BMINF的後訓練量化實現