nss-day-cohort-46 / How-to-Ask-for-Help

0 stars 0 forks source link

Maximum update depth exceeded. #199

Closed Loganwebb1994 closed 3 years ago

Loganwebb1994 commented 3 years ago

Ticket MUST be completed before getting help from an instructor

Name: Logan

Breakout Room: mine

Have you searched the other issue tickets? If not, do that first.

REQUIRED Add Tags to Issue Ticket and Assign to Project Board

REQUIRED Describe your issue:

I was trying to make a component to display a filtered list of stands. When I created the route to go back to the main page I got an error saying I have an infinite loop somewhere.

REQUIRED Copy/paste any error messages that appear:

REQUIRED What have you googled? (You must have at least 3 links related to your issue)

REQUIRED: What have you tried? Tell us everything you have tried.

I have tried looking through my code for errors but i didnt add any new use effects or state variables that would cause the loop

REQUIRED: Copy/paste link TO THE FILE on your branch that you are having issues with

https://github.com/Loganwebb1994/oh-deer/blob/LW-notes-addNote/src/components/stands/AvailableStands.js

Code Snippet

export const AvailableStands = () => {
  const history = useHistory()
  const { stands, getStands, getUserStands, userStands, getUsers } = useContext(StandContext)

  useEffect(() => {
    getUsers()
    }, [])

  useEffect(() => {
    getUserStands()
    .then(getStands())

  }, [])

  const filteredStands = stands.filter(stand => stand.availability === true)

  return (
  <>
  <button onClick={history.push("/")}>All Stands</button>
    <div className="standList">
      {
        filteredStands.map(stand => { let notesForStand = userStands.filter(userStand => userStand.standId === stand.id  )
          return <StandCard key={stand.id} stand={stand} relationships={notesForStand} />
        })
      }
    </div>
  </>
  )
}
Loganwebb1994 commented 3 years ago

Also My page goes straight to my /available-stands path instead of defaulting to /

Loganwebb1994 commented 3 years ago

you need () => before the history.push()