Avik Biswas
Avik Biswas

Reputation: 19

Error : Expected to return a value at the end of arrow function

Expected to return a value at the end of arrow function , this is a common problem one can face easily while using react JSX in strict mode

contentType = id => {

console.log('')

if (id === 'COURSE') {
  return <div>{id}</div>
}
if (id === 'PROJECT') {
  return <div>{id}</div>
}   

}

Upvotes: 0

Views: 33

Answers (1)

Avik Biswas
Avik Biswas

Reputation: 19

right ans is

contentType = id => { console.log('')

if (id === 'COURSE') {
  return <div>{id}</div>
}
if (id === 'PROJECT') {
  return <div>{id}</div>
}
return ''  

}

dont leave without no return at the end , at react strict mode this happen , last and default condition always goes at the end with no extra block

Upvotes: 0

Related Questions