Skip to content
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

how to bind selected value in initial #169

Open
loki13111997 opened this issue Feb 18, 2022 · 1 comment
Open

how to bind selected value in initial #169

loki13111997 opened this issue Feb 18, 2022 · 1 comment

Comments

@loki13111997
Copy link

No description provided.

@andre-wells
Copy link

I have a similar issue on this.

Initial value set to -1 on mount and then updated after async load of options and value. But even though I'm passing the "current" value as props, the initial value isn't updated.

export interface IRadioOption<T> {
  label: string;
  value: T;
}

interface IProps<T extends string | number> {
  value?: T;
  options: IRadioOption<T>[];
  onPress: (id?: T) => void;
}

const RadioButtonGroup = <T extends string | number>({value, options, onPress}: IProps<T>) => {
  return (
    <RadioForm
      radio_props={options}
      // @ts-ignore prop not declared on component but is used
      selectedButtonColor={Colors['primary-600']}
      selectedButtonInnerColor={Colors['primary-600']}
      buttonColor={Colors['gray-300']}
      buttonSize={10}
      initial={value ? options.map(x => x.value).indexOf(value) : -1}
      labelStyle={tw`text-gray-700 font-poppinsMedium`}
      onPress={(index: number) => {
        onPress(options.find(x => x.value === index)?.value);
      }}
    />
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants