Creates a state based on an AWML dynamic value. The returned state value will
change whenever the dynamic value changes. The returned setter will - when
called - call .set()
on the dynamic value.
const [value, setValue] = useDynamicValue(dynamicValue, defaultValue, replay);
dynamicValue
: DynamicValue
- The dynamic value to subscribe to.defaultValue
: any
- The default value of the state. If the dynamic value initially already has a value, it is used instead ofdefaultValue
.replay
: boolean
- Used as the second argument toDynamicValue.subscribe
. This means that, if set tofalse
, the current value of the dynamic value is not ignored. Defaults totrue
.
import { useDynamicValue } from '@deutschesoft/use-aux-widgets';
function Channel(props) {
const { mute$ } = props;
const [muted, setMuted] = useDynamicValue(mute$);
const onClick = () => {
setMuted(!muted);
};
return (
<div className="channel">
<button onClick={onClick}>{muted ? 'Muted' : 'Not Muted'}</button>
</div>
);
}