简体   繁体   中英

change callback function with diffrent name in javascript

i want to use stop function in useSound Hooks in diffrent name because i alredy used stop variable.

Use Sound Doc

import play from "./assets/play.mp3";

const [Phone,{stopPhone as stop }] = useSound(phone);

您应该像这样使用对象解构

const [Phone, { stop: stopPhone }] = useSound(phone);

If useSound returns an array, there should be no need to "rename" any of its items - simply put in the names you want into the destructuring syntax:

const [Phone,stopPhone] = useSound(phone);

you can simply choose whatever names you wish.

If it returns an object you can use object destructuring as follows

const [Phone,{ stop: stopPhone }] = useSound(phone);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM