当前位置:网站首页>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 )
边栏推荐
- TDengine 社区问题双周精选 | 第三期
- KDD 2022论文合集(持续更新中)
- Tdengine biweekly selection of community issues | phase III
- Niuke winter vacation training 6 maze 2
- Post training quantification of bminf
- xargs命令的基本用法
- [OC foundation framework] - [set array]
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- Cesium draw points, lines, and faces
- LeetCode:41. 缺失的第一个正数
猜你喜欢
Alibaba cloud server mining virus solution (practiced)
[embedded] cortex m4f DSP Library
Mise en œuvre de la quantification post - formation du bminf
Selenium+pytest automated test framework practice
Selenium+Pytest自动化测试框架实战
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
Computer graduation design PHP Zhiduo online learning platform
什么是MySQL?MySql的学习之路是怎样的
Mongodb installation and basic operation
随机推荐
[sword finger offer] serialized binary tree
LeetCode:劍指 Offer 42. 連續子數組的最大和
LeetCode:221. Largest Square
Intel distiller Toolkit - Quantitative implementation 1
Navicat Premium 创建MySql 创建存储过程
LeetCode:673. Number of longest increasing subsequences
xargs命令的基本用法
随手记01
如何正确截取字符串(例:应用报错信息截取入库操作)
Selenium+Pytest自动化测试框架实战(下)
Pytest之收集用例规则与运行指定用例
[OC-Foundation框架]-<字符串And日期与时间>
Ijcai2022 collection of papers (continuously updated)
在QWidget上实现窗口阻塞
LeetCode:162. Looking for peak
R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
R language ggplot2 visualization, custom ggplot2 visualization image legend background color of legend
CSP first week of question brushing
LeetCode:162. 寻找峰值
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born