Ok, ya veo, yo nunca he sido fan de cambiar la estructura de mis objetos. Yo haría
const stateData = countryData.regions.find(
state => state.name === stateName
)
return countryData && stateData
? {
countryName: countryData.countryName,
countryCode: countryData.countryShortCode,
stateName: stateData.name,
stateCode: stateData.shortCode,
}
: {
countryName: "notFound",
countryCode: "notFound",
stateName: "notFound",
stateCode: "notFound",
}