. Advertisement .
..3..
. Advertisement .
..4..
I got this message “expected an assignment or function call and instead saw an expression” when I run the code bellow:
App.js
const App = props => {
const result = ['a', 'b', 'c'].map(el => {
// ⛔️ Expected an assignment or function call and instead saw an expression. eslint no-unused-expressions
el + '100';
});
return <div>hello world</div>;
};
const mapStateToProps = (state) => {
// ⛔️ Expected an assignment or function call and instead saw an expression. eslint no-unused-expressions
todos: ['walk the dog', 'buy groceries']
}
export default App;
I don’t know where I went wrong, looking forward to the answer. Thanks for everyone’s help.
The cause: The
Array.map()
method in theApp
component is where the error is generated. You failed to supply a value from themapStateToProps
function, which is the problem.Solution: Either an explicit
return
statement or the use of an arrow function to indirectly return a value will fix the problem. The error can be fixed with an explicitreturn
, as seen in the following example.Follow the article below to understand more
👇️ Resolve error: “Expected an assignment or function call and instead saw an expression”