-1

The app i made is a movie website that shows movies based on your search. You can also add favorites, however its not linked to your profile. So the solution i came up with was to make another value in the profile initial state in redux.

export const profileInitialState = [
{pass: '123', user: 'daniel', email: 'daniel@123.com', favourites: 'batman' },
]

interface IProfileState {
    pass: string, 
    user: string,
    email: string,
    favourites?: string
}

and just map it from there

{data.profileReducer.slice(data.profileReducer.indexOf( {user: currUser, pass: password, email: email}, 1)).map(info =>
  <p key={data.profileReducer.length + 1.5} > {info.favourites} </p>)}

and even thought it works perfectly in the console, it tell me profileReducer.indexOf is not a function when i implement it in my code.

FunkeMunk
  • 1
  • 3
  • Try to log `data.profileReducer`, e.g: `console.log(data.profileReducer)`, it could be null, or undefined. also make sure it is an array. – Mehdi Dehghani Jan 16 '20 at 12:13
  • i logged it and it is an array, but it is also undefined next to the state interface in the reducer **const profileReducer: (state: IProfileState[] | undefined, action: ActionTypes)** – FunkeMunk Jan 16 '20 at 12:49
  • If you add this: `console.log(data.profileReducer)`, what would be the the result in browser console? – Mehdi Dehghani Jan 16 '20 at 13:09
  • `Array[ Object ]` was returned when console logging it – FunkeMunk Jan 16 '20 at 13:17

1 Answers1

0

First of all, Array.prototype.indexOf() can't be used to find the index of object elements in the array.

How to get index of object by its property in JavaScript?. This link describes how you can get the index of array elements.

The error can be caused by a few reasons

  • data.profileReduceris undefinded or null
  • data.profileReducer is not an array
Raison
  • 21
  • 6