1- import React , { forwardRef , HTMLAttributes , useState , useEffect , useRef } from 'react'
1+ import React , {
2+ createContext ,
3+ forwardRef ,
4+ HTMLAttributes ,
5+ useState ,
6+ useEffect ,
7+ useRef ,
8+ } from 'react'
29import PropTypes from 'prop-types'
310import classNames from 'classnames'
411
@@ -68,7 +75,7 @@ interface DataType {
6875 timeout ?: null | ReturnType < typeof setTimeout >
6976}
7077
71- export interface ContextType {
78+ export interface ContextProps {
7279 itemsNumber : number
7380 state : [ number | null , number , string ?]
7481 animating : boolean
@@ -78,16 +85,7 @@ export interface ContextType {
7885 setState : ( a : [ number | null , number , string ?] ) => void
7986}
8087
81- //
82-
83- export const Context = React . createContext < ContextType > ( {
84- itemsNumber : 0 ,
85- state : [ null , 0 ] ,
86- animating : false ,
87- setItemsNumber : ( _ ) => { } ,
88- setAnimating : ( _ ) => { } ,
89- setState : ( _ ) => { } ,
90- } )
88+ export const CCarouselContext = createContext ( { } as ContextProps )
9189
9290export const CCarousel = forwardRef < HTMLDivElement , CCarouselProps > (
9391 (
@@ -110,7 +108,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
110108 const [ itemsNumber , setItemsNumber ] = useState < number > ( 0 )
111109 const [ animating , setAnimating ] = useState < boolean > ( false )
112110
113- let data = useRef < DataType > ( { } ) . current
111+ const data = useRef < DataType > ( { } ) . current
114112
115113 const cycle = ( ) => {
116114 pause ( )
@@ -147,7 +145,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
147145
148146 return (
149147 < div className = { _className } onMouseEnter = { pause } onMouseLeave = { cycle } { ...rest } ref = { ref } >
150- < Context . Provider
148+ < CCarouselContext . Provider
151149 value = { {
152150 state,
153151 setState,
@@ -166,7 +164,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
166164 < CCarouselControl direction = "next" />
167165 </ >
168166 ) }
169- </ Context . Provider >
167+ </ CCarouselContext . Provider >
170168 </ div >
171169 )
172170 } ,
0 commit comments