Tengo 3 componentes funcionales y me gustaría pasar y manipular datos a través de useRef .
Estoy agregando este método onClose a la propiedad current en uno de mis componentes.
const onClose = () => { setButtonColor(buttonColor); }; ref.current = { clearSwitchStateOnClose: onClose, };Estoy llamando a ese método en otro componente.
ref.current.clearSwitchStateOnClose();Estoy recibiendo este error,
Uncaught TypeError: ref.current.clearSwitchStateOnClose is not a functionEstaba llamando a este método ref.current.clearSwitchStateOnClose(); pero con eso también estaba mutando ref . Supongo que eso estaba causando el problema.
era algo asi,
ref.current = { showModal: false, modalResponse: null, }; ref.current.clearSwitchStateOnClose();Después de hacer esto, está funcionando bien.
ref.current.clearSwitchStateOnClose(); ref.current = { showModal: false, modalResponse: null, };Perdón por no compartir todo el escenario de esta situación.