-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React/radio controllers #378
React/radio controllers #378
Conversation
|
||
export default ({ url, duration }: IProps): IUseAudio => { | ||
const [audio] = React.useState(new Audio()); | ||
const [, _forceUpdate] = React.useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forceUpdateが何をしているのかちょっとよく分からなかったので教えてほしいです!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
内部状態に変更があった時に直前の真偽値とは逆の値をセットすることで必ず再レンダリングさせるためです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webAPIにあんまり詳しくないから教えてほしいんだけど、
addEventListener
やremoveEventListener
の第2引数にboolを渡したらどんな挙動になるんです?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第2引数に渡しているのはconst forceUpdate = () => _forceUpdate(prevState => !prevState);
という関数でboolは渡してないです。
この関数を渡すことでaudio.currentTimeなどの値が変わると必ず再レンダリングされます。
これがないとaudio.currentTime等が更新されないのでシークバーなども再レンダリングされません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに、boolじゃなかった、
この関数を渡すことでaudio.currentTimeなどの値が変わると必ず再レンダリングされます。
これがないとaudio.currentTime等が更新されないのでシークバーなども再レンダリングされません。
なぜこのtoggleしている?関数を渡すと再レンダリングされるようになるのかがよく分かっていない、、、
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stateが変われば再レンダリングされるっていう仕様を使ってcurrentTimeとかをobserveしてるのね、なるほど
トリッキーな感じがするけどこれが普通なのかな、、
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useCallback
を使うのが正しそう?
https://ja.reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにuseCallback
の方が正しそう
別PRで修正してもいいですか?
一旦このRadioCard系を潰したいです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
別PRで修正してもいいですか?
OK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
→#380
useAudioの参考URL |
|
||
export default ({ url, duration }: IProps): IUseAudio => { | ||
const [audio] = React.useState(new Audio()); | ||
const [, _forceUpdate] = React.useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あーちょっと分かってきたかもしれない!
|
||
export default ({ url, duration }: IProps): IUseAudio => { | ||
const [audio] = React.useState(new Audio()); | ||
const [, _forceUpdate] = React.useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stateが変われば再レンダリングされるっていう仕様を使ってcurrentTimeとかをobserveしてるのね、なるほど
トリッキーな感じがするけどこれが普通なのかな、、
cx={params.width / 2} | ||
cy={params.height / 2} | ||
r={params.radius - 2} | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めちゃくちゃcircleを作っている...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あのデザインは難しかった
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多分良いと思う!お疲れさま!
マージしますー! |
closed #323
WHAT
やったこと
/hooks/useAudio
の作成 (preload="none"対応済み ref: Modify preload=metadata -> preload=none #278 )