score:1
Accepted answer
The map
function, as the warning says, is always expected to return a value, at every iteration. Your function returns something only when the condition inside the if statement is true. In all other cases, nothing is returned.
To fix that, you can just add an else statement:
if (each !== 'logo' && each !== 'info' && each !== 'mobin') {
...
} else {
return null;
}
Another option is to remove if
from within the map
function and use the filter
function like this:
{props && Object.keys(props)
.filter(each => each !== 'logo' && each !== 'info' && each !== 'mobin')
.map(each => {
return(
......
)})
}
score:0
You can also get rid of the explicit if statement:
{
props &&
Object.keys(props).map((each) => {
return (
each !== 'logo' &&
each !== 'info' &&
each !== 'mobin' && (
<Slide key={each} style={{ height: '200px' }}>
<div
style={{
height: '100%'
}}
onClick={() => handleClick(each)}
className="d-flex justify-content-center align-items-center"
>
<Img
alt="company-logo"
style={{
width: '140px',
cursor: 'pointer'
}}
fluid={props[each].childImageSharp.fluid}
/>
</div>
</Slide>
)
);
});
}
Source: stackoverflow.com
Related Query
- How to fix expected to return a value at the end of arrow function warning in react js?
- Expected to return a value at the end of arrow function on reactjs how to fix this error?
- react warning Expected to return a value at the end of arrow function array-callback-return
- How to fix linter expected to return a value at the end of react function component?
- warning Expected to return a value at the end of arrow function
- How do I fix "Expected to return a value at the end of arrow function" warning?
- How fix this warrning warning Array.prototype.map() expects a return value from arrow function array-callback-return?
- Expected to return a value at the end of arrow function with if statement
- Expected to return a value at the end of arrow function array-callback-return on filter function
- How should I fix "Expected to return a value at the end of arrow function."?
- How fix warning "Expected to return a value in arrow function array-callback-return"
- React JS - Expected to return a value at the end of arrow function ES lint Error
- 118:51: Expected to return a value at the end of arrow function array-callback-return
- Expected to return a value at the end of arrow function in react
- Expected to return a value at the end of this function array-callback-return in React JS
- How to fix "Array.prototype.filter() expects a value to be returned at the end of arrow function"
- Should I return true to clear .map() expects a value to be returned at the end of arrow function warning?
- How to tell TS explicitly that the return value of a function will be expected to be of a certain type?
- How to fix "Expected to return a value in arrow function array-callback-return"?
- How to fix "Expected to return a value in arrow function" with reactjs?
- Async arrow function expected no return value
- How to fix 'Expected the return value to be a 31-bit integer' error react hooks
- How do I fix a React TypeScript error with the return value of useHotkeys hook not matching the type of the div element ref prop
- Array.prototype.filter() expects a value to be returned at the end of arrow function
- How to return 2 function calls in the arrow function at once?
- How to get the return value of a async function that returns a promise
- How to store the return value of a function inside a variable in reactJS
- How to pass the return value of a function as a property to a react component
- How to get the return value of parent function to child component in react (Using props)
- Array.prototype.map() expects a value to be returned at the end of arrow function
More Query from same tag
- How could I hide api key in my React app and host the working version in Github
- TypeError: Cannot read property 'value' of undefined on components (ReactJS forms)
- React CSSTransitionGroup is not working (doesn't add classes)
- Can I set the Recharts axis domain max lower than dataMax?
- react history.push does not work neither does useHistory
- reactjs - this is not a function error on upgrade
- How to get document id and document data?
- Retrieve row value selected in a Table as an array and send the results to another function on React
- How to extend JSX.IntrinsicElements['div']? TS2499
- Typescript types for Prismic Slices
- Trying to use mock function when testing React component
- React SPFx - Adding files to SharePoint list field using PnPjs
- how to create multiple Routes component in reactjs
- react component renders twice with only one setState in componentWillMount
- Inline SVGs in React components not showing
- React - Render Link within JSX markdown returning [object Object]
- Validate a nested component in a fieldArray using react-hook-form
- useLocation() is not working even inside the Router context
- Next JS bootstrapping
- How do I conditionally render a component in Gatsby based on specific page?
- How to query for a signed in user's data in Graphql and AWS Cognito
- how to make a vertical slide of text in React
- using react-md with meteor
- deploying create-react-app to heroku with express backend returns invalid host header in browser
- How to target DOM and change style in react with mapped elements
- Create a multidimensional list from Array Objects
- TypeError: cannot read property setState of undefined
- how to test react-select with react-testing-library
- Can I use both ES6 and ES5 in the same React codebase?
- Redux toolkit filter() not working when wanting to display new array at the same time