react formik conditional render initial values

3k views Asked by At

I want to render a value if my Id is true if the Id is false the value shouldnt exist, is it possible to render what values formik

initialValues={{
                    id:currentBankData.id || '',
                    name: currentBankData.name || '',
                    address: currentBankData.address || '',
                    country: currentBankData.country || '',
                    region: currentBankData.region || '',
                    city: currentBankData.city || '',
                    swiftCode: currentBankData.swiftCode || '',
                    routeCode: currentBankData.routeCode || '',
                    
                    //Example want to do something like this
if(Id){
    imageBinairyData: currentBankData.image ||'' ,
}else{
image: currentBankData.image || '',
}
                }}
1

There are 1 answers

0
ChrisJnr Potgieter On BEST ANSWER
initialValues={{
  id:currentBankData.id || '',
  name: currentBankData.name || '',
  address: currentBankData.address || '',
  country: currentBankData.country || '',
  region: currentBankData.region || '',
  city: currentBankData.city || '',
  swiftCode: currentBankData.swiftCode || '',
  routeCode: currentBankData.routeCode || '',
  [Id ? 'imageBinairyData' : 'image']: currentBankData.image || '',
}}