react-native-bouncy-checkbox icon indicating copy to clipboard operation
react-native-bouncy-checkbox copied to clipboard

state management

Open ibrar-web opened this issue 2 years ago • 6 comments

checkbox only update state if we click box otherwise checkbox don't update state

ibrar-web avatar Aug 16 '22 06:08 ibrar-web

Hello @ibrar-web I don't exactly understand what do you mean. Do you want to update the checkbox with ref?

WrathChaos avatar Aug 16 '22 06:08 WrathChaos

i think it is the same problem as the last issue (ref problem). is it hard to fix? @WrathChaos

VitorGbrl avatar Aug 18 '22 00:08 VitorGbrl

I will take a look at this today Sorry for late response tho

WrathChaos avatar Aug 18 '22 07:08 WrathChaos

Hey again @VitorGbrl There is a disable built-in state prop. Have you tried it? Otherwise, I really need a code example to fix this

WrathChaos avatar Aug 26 '22 15:08 WrathChaos

@WrathChaos

I have a login screen (see below for source code) where I am disabling a login button util the user accepts a EULA agreement by clicking the checkbox. The code works, but I get the following TS error:

Type 'boolean | (() => void)' is not assignable to type '((checked: boolean) => void) | undefined'. Type 'boolean' is not assignable to type '(checked: boolean) => void'.

Any advice on how I can fix this?

//useToggle.ts import { useCallback, useState } from 'react'; export const useToggle = (initialState = false) => { const [state, setState] = useState(initialState); const toggle = useCallback(() => setState((prevState) => !prevState), []); return [state, toggle]; };

//LoginScreen.tsx export const LoginScreen = (): JSX.Element => { const [termsAccepted, setTermsAccepted] = useToggle(); return ( <View.Safe style={loginScreenStyles.container} edges={['left', 'right']}> <LoginHeader /> <View.Column style={loginScreenStyles.loginContainer}> <Text style={loginScreenStyles.tagline}>{constants.auth.welcomeText}</Text> <LoginButton onPress={onLogin} disabled={!termsAccepted} /> <View.Row> <BouncyCheckbox onPress={setTermsAccepted} /> <EulaAgreement /> </View.Row> </View.Column> </View.Safe> ); };

omniviewsports avatar Sep 26 '22 16:09 omniviewsports

@WrathChaos

I have a login screen (see below for source code) where I am disabling a login button util the user accepts a EULA agreement by clicking the checkbox. The code works, but I get the following TS error:

Type 'boolean | (() => void)' is not assignable to type '((checked: boolean) => void) | undefined'. Type 'boolean' is not assignable to type '(checked: boolean) => void'.

Any advice on how I can fix this?

//useToggle.ts import { useCallback, useState } from 'react'; export const useToggle = (initialState = false) => { const [state, setState] = useState(initialState); const toggle = useCallback(() => setState((prevState) => !prevState), []); return [state, toggle]; };

//LoginScreen.tsx export const LoginScreen = (): JSX.Element => { const [termsAccepted, setTermsAccepted] = useToggle(); return ( <View.Safe style={loginScreenStyles.container} edges={['left', 'right']}> <View.Column style={loginScreenStyles.loginContainer}> {constants.auth.welcomeText} <View.Row> </View.Row> </View.Column> </View.Safe> ); };

Please continue with your own issue :) Thank you

WrathChaos avatar Sep 30 '22 09:09 WrathChaos