Skip to content

Commit c166fc2

Browse files
committed
refactor: Use sintax with function clear
1 parent b834d5c commit c166fc2

2 files changed

Lines changed: 9 additions & 24 deletions

File tree

src/Item.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default ({ children, increaseValue, decreaseValue, setViewValue }) => {
44
const [x, setX] = useState(0);
55
const [viewX, setViewX] = useState(0);
66

7-
const ref = createRef();
7+
const itemRef = createRef();
88

99
const getTouches = (evt) => evt.touches;
1010

@@ -49,7 +49,7 @@ export default ({ children, increaseValue, decreaseValue, setViewValue }) => {
4949
<div
5050
draggable
5151
class="item-content"
52-
ref={ref}
52+
ref={itemRef}
5353
onTouchMove={handleTouchMove}
5454
onTouchStart={handleTouchStart}
5555
onTouchEnd={handleTouchEnd}

src/ReactCarousel.jsx

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,26 @@ import React, { createRef, useEffect, useState } from "react";
22
import Item from "./Item.jsx";
33
import style from "./style";
44

5-
export default ({
6-
value = 0,
7-
setValue,
8-
children,
9-
navigation,
10-
}) => {
5+
export default ({ value = 0, setValue, children, navigation }) => {
116
const [viewValue, setViewValue] = useState(0);
127

138
const firstItemRef = createRef();
149
const carousel = createRef();
1510

16-
const increaseValue = () => {
17-
if (value !== children.length - 1) {
18-
setValue(value + 1);
19-
}
20-
};
11+
const increaseValue = () =>
12+
value !== children.length - 1 && setValue(value + 1);
2113

22-
const decreaseValue = () => {
23-
if (value !== 0) {
24-
setValue(value - 1);
25-
}
26-
};
14+
const decreaseValue = () => value !== 0 && setValue(value - 1);
2715

2816
const moveCarousel = (value, duration) => {
2917
const firstItemStyle = firstItemRef.current.style;
3018
firstItemStyle.transitionDuration = duration;
3119
firstItemStyle.marginLeft = value;
3220
};
3321

34-
const canMove = () => {
35-
return (
36-
(viewValue < 0 && value !== 0) ||
37-
(viewValue > 0 && value !== children.length - 1)
38-
);
39-
};
22+
const canMove = () =>
23+
(viewValue < 0 && value !== 0) ||
24+
(viewValue > 0 && value !== children.length - 1);
4025

4126
useEffect(() => {
4227
if (canMove(viewValue))

0 commit comments

Comments
 (0)