0

I have a dashboard page that shows a table list of all the posts, for each post I have and an edit button.

I'm trying to pop a modal when the edit button is clicked. So I created a Modal component, which is rendered by the Dashboard component (this is a high order component equal to the App compo) and I added a modal slice with redux toolkit and I successfully managed to change the modal state when the edit button is clicked but the modal doesn't show up. I hope that I was thorough enough with what I'm trying to achieve, I also hope that you will help me guys, and now I'll share with you some of the code.

EditPostModal.jsx

import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { makeStyles } from '@material-ui/core/styles'
import Modal from '@material-ui/core/Modal'
import editPostSlice, {
  getPostToEditModal,
} from '../../store/slices/editPost'

const useStyles = makeStyles((theme) => ({.....}))

export default function SimpleModal() {
  const classes = useStyles()
  const modal = useSelector(getPostToEditModal)
  const dispatch = useDispatch()
  console.log('HEYYYY', modal) // modal is undefined

  const handleClose = () => {
    dispatch(editPostSlice.actions.closeModal())
  }

  if (!modal) return null

  return (
    <Modal
      className={classes.modal}
      open
      onClose={handleClose}
      aria-labelledby="simple-modal-title"
      aria-describedby="simple-modal-description"
    >
      <h1>I AM THE MODAL</h1>
    </Modal>
  )
}

1 Answer 1

1

The first step to debug is to check if the modal will open without redux toolkit slice.

Also, can you confirm that the modal variable always return something other than a falsy value?

Sign up to request clarification or add additional context in comments.

1 Comment

I fixed it, it turns out that the issue was in editPostSlice, I wasn't fetching the modal state correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.