useMemoを使用すると
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
というエラーがでます。
以下がコードです。
どこが悪いのでしょうか?
function arrange_video_current_time() { let timeH = Math.floor( (Math.round(currentTimeSlider) % (24 * 60 * 60)) / (60 * 60), ); let timeM = Math.floor( ((Math.round(currentTimeSlider) % (24 * 60 * 60)) % (60 * 60)) / 60, ); let timeS = ((Math.round(currentTimeSlider) % (24 * 60 * 60)) % (60 * 60)) % 60; let timeHMS = () => { if (timeH != 0) { return timeH + ':' + padZero(timeM) + ':' + padZero(timeS); } else return timeM + ':' + padZero(timeS); }; return timeHMS(); function padZero(v: number) { if (v < 10) { return '0' + v; } else { return v; } } } const [currentTimeSlider, setCurrentTimeSlider] = useState(0); function unifiedValueChange(value: number) { //useMemoのコードはじまり useMemo(() => { setCurrentTimeSlider(value); }, [currentTimeSlider]); return; } //useMemoのコード終わり return ( <Text style={{ color: 'white', paddingRight: 5, fontWeight: 'bold', }}> {arrange_video_current_time()} </Text> <Slider style={{ width: '50%', transform: [{ scaleY: 0.8 }], }} minimumValue={0} maximumValue={movie?.duration_second} minimumTrackTintColor="#4169e1" maximumTrackTintColor="#ddd" thumbTintColor="#4169e1" onSlidingStart={unifiedOnSlidingStart} onValueChange={unifiedValueChange} onSlidingComplete={unifiedOnSlidingComplete} step={movie?.duration_second / 10} value={currenttime} />
何卒よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー