-
Notifications
You must be signed in to change notification settings - Fork 44
/
App.js
36 lines (32 loc) · 986 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { useState, useEffect, useRef } from 'react';
import RangeSlider from 'svelte-range-slider-pips';
// import type { ComponentProps } from 'svelte';
// import type { RangeSlider as RangeSliderType } from 'svelte-range-slider-pips';
export default function MyComponent() {
const [values, setValues] = useState([33, 66]);
const MySlider = useRef();
const $node = useRef();
useEffect(() => {
if (!MySlider.current) {
MySlider.current = new RangeSlider({
target: $node.current,
props: { values: values, range: true }
});
MySlider.current.$on('change', (e) => {
setValues(e.detail.values);
});
}
}, []);
function handleClick() {
const newVals = values.map((v) => v + 10);
setValues(newVals);
MySlider.current.$set({ values: newVals });
}
return (
<div>
<h1>{values.join(',')}</h1>
<div ref={$node}></div>
<button onClick={handleClick}>Add 10</button>
</div>
);
}