Skip to content

set default value from existing resource #44

Description

@andresfmm

i hope can help someone if you want set value default from a existing resource you can this way how explin in documentation

const [countries, setCountries] = React.useState([
{ id: '22946344-f6be-11ed-8207-9828a60f7a9e', name: 'node js'},
{ id: '123456789', name: 'php'}
]);

const id = '22946344-f6be-11ed-8207-9828a60f7a9e';

countries.forEach(function(item){

    if ( item.id ==  id ) {
         item.checked = true;
    }

});

setCountries(countries);

<Select2
style={{ borderRadius: 5, marginTop: 20 }}
isSelectSingle
cancelButtonText="Cancelar"
selectButtonText="Aceptar"
searchPlaceHolderText="Buscar"
colorTheme={theme.colors.primary}
popupTitle="Seleccione "
title="Selecionar barrio"
data={countries}
onSelect={(data:any) => {
setState(data)
}}
onRemoveItem={(data:any) => {
setState(data)
}}
/>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions