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

0 stars 0 forks source link

Notes not rendering on DOM #187

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: The Hackery

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:

Im mapping through the stands and filtering through my userStands to try and render all stands, then if the stand has a note, render that note. I checked in the browser and im not getting any errors.

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 just filtering and I've tried to filter, push filtered results to an array and then pass the variable that contains the array of related user stands as an argument on my stand card.

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/StandList.js

Code Snippet

export const StandList = () => {

  const { stands, getStands, getUserStands, userStands, getUsers } = useContext(StandContext)

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

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

  }, [])

    console.log(userStands)
  let notesForStand = []

  return (

    <div className="standList">
      {
        stands.map(stand => { userStands.filter(userStand => userStand.standId ===stand.id? notesForStand.push(userStand) : "" )
          return <StandCard key={stand.id} stand={stand} relationship={notesForStand} />
        })
      }
    </div>
  )
}
Loganwebb1994 commented 3 years ago
 return (

    <div className="standList">
      {
        stands.map(stand => { let notesForStand = userStands.filter(userStand => userStand.standId === stand.id  )
          {console.log(notesForStand, "standNote")}
          return <StandCard key={stand.id} stand={stand} relationship={notesForStand} />
        })
      }
    </div>
  )
}

updated code, still not working. My filter isnt returning anything

Loganwebb1994 commented 3 years ago

My issue was that I was trying to pass in an array of multiple objects as an argument. Once I mapped through that array and accessed the individual objects the notes rendered.