Like to conditionally render an initialValue in formik

773 views Asked by At

I'm having trouble understanding Formik and conditionally rendering some of the items Like to conditionally render an initial value in formik keep telling me that image is undefined when in the if statement

<Formik
                enableReinitialize={true}

                

                initialValues={{
                    
                    name: currentBankData.name || '',
                    address: currentBankData.address || '',
                    country: currentBankData.country || '',
                    region: currentBankData.region || '',
                    city: currentBankData.city || '',
                    swiftCode: currentBankData.swiftCode || '',
                    routeCode: currentBankData.routeCode || '',
                    
                    
                
        
                    image: currentBankData.image || ''

            
                    
                    /*Something Like this
                    baniId ? (
                    image: currentBankData.image || ''   
                    ) : ("")
                    */
                    



                }   

            }
            
1

There are 1 answers

0
rockingskier On BEST ANSWER

Is this what you mean? If baniId then currentBankData.image otherwise ''

initialValues={{
    // ...
    image: baniId ? currentBankData.image : ''
    // ...
 }}