Category : conditional-operator

My Code { countries.length ? filteredCountries(searchVal, countries).length <= 10 ? filteredCountries(searchVal, countries).map(country => <p key={country.name}>{country.name}</p>) : <span>please be more specific, add filter…</span> : <span>populating countries data…</span> } I want to add a condition to display ‘type to search’ when searchVal is an ”. I can put it in English but cant get the code equivalent, ..

Read more

I’m fetching data from an api, and then use my search component to filter through the data. { countries.length ? (searchVal ? countries.filter(country => country .name .toLowerCase() .includes(searchVal.toLowerCase())) : countries ).map(country => (country) => <p key={country.name}>{country.name}</p>) : ‘populating the world…’ } I want to chain ternary operators, as you can see. I get the following ..

Read more

I have the following ternary code snippet that conditionally renders a React Fragment as shown below: { jobName === ‘ABC’ ? ( <React.Fragment> <FieldArray name="myGroups"> {({ push, remove}) => ( <React.Fragment> <Grid item xs={12}> <Typography variant="h6"> My Heading </Typography> </Grid> )} </FieldArray> </React.Fragment> ) : null } My question is, as part of the else ..

Read more

so, I heard there are no ternary operators in kotlin, so, how can I achieve the following in kotlin data class JS {online.map(function(item){ return ( <div key={item.uid} > {item.Gender== ‘Male’ ? <li > <div><img src={item.photoURL}/><p><b>{item.displayName}</b></p></div> </li> : null} </div> ) })} online is an object that contains the list of user information {item.Gender === ‘Male’ ..

Read more

Is there a way to execute the following code, without specifying ‘a’ twice? const result = a > b ? a : default; Useful for when the ternary is inside an arrow function and ‘a’ is an arithmetic operation the uses the function parameters: someFunc((value) => value + otherValue / 10 > b ? value ..

Read more