第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從 React 中的其他頁(yè)面打開對(duì)話框

從 React 中的其他頁(yè)面打開對(duì)話框

冉冉說(shuō) 2022-09-29 17:11:20
當(dāng)我單擊用戶列表中的“刪除”功能按鈕時(shí),我正在打開一個(gè)對(duì)話框組件。當(dāng)我單擊它時(shí),應(yīng)該顯示對(duì)話框組件。我的問(wèn)題是為什么我不能打開它。我正在使用 redux 將數(shù)據(jù)傳遞給它。請(qǐng)看這個(gè)代碼和框鏈接點(diǎn)擊這里import { dialogConstants } from "../constants";export const initialState = {  title: null,  details: null,  isOpen: null};const dialogReducer = (state = initialState, action) => {  console.log(action.payload);  switch (action.type) {    case dialogConstants.SET_DIALOG_DETAILS:      return {        ...state,        isOpen: action.payload.isOpen,        title: action.payload.title,        details: action.payload.details      };    default:      return state;  }};export default dialogReducer;
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

您沒(méi)有在 中導(dǎo)入 。因此,當(dāng)您單擊按鈕時(shí),對(duì)話框?qū)⒉粫?huì)打開。試試這個(gè): 在 :Dialogsuser.jsuser.js


...

import DeleteDialog from "./dialog";


import { useDispatch } from "react-redux";

import { deleteUser } from "./actions";


export default function User() {

  const dispatch = useDispatch();

  const [selectedUser, setSelectedUser] = React.useState({});

  const [open, setDialogOpen] = React.useState(false);


  const handleOnDelete = user => {

    setSelectedUser(user);

    setDialogOpen(true);

  };


  const handleOnAgree = () => {

    // do action to handle on agree deleting an user

    dispatch(deleteUser({ title: "Delete User", details: selectedUser }));

    setDialogOpen(false);

  };


  return (

    <div>

      <Paper>

        <TableContainer>

          <Table stickyHeader aria-label="sticky table">

            <TableHead>

              <TableRow>

                <TableCell>First Name</TableCell>

                <TableCell>Last Name</TableCell>

                <TableCell>Email Address</TableCell>

                <TableCell>Actions</TableCell>

                <TableCell />

              </TableRow>

            </TableHead>

            <TableBody>

              <TableRow>

                <TableCell>JJJ</TableCell>

                <TableCell>BBB</TableCell>

                <TableCell>enfoie</TableCell>

                <TableCell>

                  <Button variant="contained">Edit</Button>

                  <Button

                    variant="contained"

                    onClick={() => handleOnDelete({ id: 1, name: "JJJ" })}

                  >

                    Delete

                  </Button>

                </TableCell>

              </TableRow>

            </TableBody>

          </Table>

        </TableContainer>

      </Paper>

      <DeleteDialog

        user={selectedUser}

        open={open}

        onAgree={handleOnAgree}

        onDisagree={() => setDialogOpen(false)}

      />

    </div>

  );

}


在:dialog.js


import React from "react";


import Button from "@material-ui/core/Button";

import Dialog from "@material-ui/core/Dialog";

import DialogActions from "@material-ui/core/DialogActions";

import DialogTitle from "@material-ui/core/DialogTitle";

import Slide from "@material-ui/core/Slide";


const Transition = React.forwardRef(function Transition(props, ref) {

  return <Slide direction="up" ref={ref} {...props} />;

});


const DeleteDialog = ({ user, open, onAgree, onDisagree }) => {

  return (

    <div>

      <Dialog

        open={open}

        TransitionComponent={Transition}

        keepMounted

        onClose={onDisagree}

        aria-labelledby="alert-dialog-slide-title"

        aria-describedby="alert-dialog-slide-description"

      >

        <DialogTitle id="alert-dialog-slide-title">

          <span style={{ fontWeight: "bold" }}>

            {" "}

            User: {user.name} - {user.id}

          </span>

        </DialogTitle>

        <DialogActions>

          <Button variant="contained" size="small" onClick={onDisagree}>

            Cancel

          </Button>

          <Button variant="contained" size="small" onClick={onAgree}>

            Confirm

          </Button>

        </DialogActions>

      </Dialog>

    </div>

  );

};


export default DeleteDialog;


查看完整回答
反對(duì) 回復(fù) 2022-09-29
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)