【发布时间】:2021-01-14 16:28:50
【问题描述】:
我正在使用 react js 和 redux 我想在点击时将星形轮廓图标更改为星形填充图标,请帮忙,因为我想不出任何可以更改它的方法,它位于 emailRow 之后和 emailRow__options 中
import { Checkbox, IconButton } from "@material-ui/core";
import { LabelImportantOutlined, StarBorderOutlined } from "@material-ui/icons";
import React from "react";
import { useDispatch } from "react-redux";
import { useHistory } from "react-router-dom";
import "../css/emailRow.css";
import { selectMail } from "../features/mailSlice";
function EmailRow({ id, title, subject, description, time }) {
const history = useHistory();
const dispatch = useDispatch();
const openMail = () => {
dispatch(
selectMail({
id,
title,
subject,
description,
time,
})
);
history.push("/mail");
};
return (
<div className="emailRow">
<div className="emailRow__options">
<Checkbox />
<IconButton>
<StarBorderOutlined />
</IconButton>
<IconButton>
<LabelImportantOutlined />
</IconButton>
</div>
<div onClick={openMail} className="emailRow__click">
<div className="emailRow__title">
<h3>{title}</h3>
</div>
<div className="emailRow__message">
<h4>
{" "}
{subject}{" "}
<span className="emailRow__description"> - {description}</span>
</h4>
</div>
<p className="emailRow__time">{time}</p>
</div>
</div>
);
}
export default EmailRow;
我怎样才能将它存储在 redux 中。谁能指导我
import { createSlice } from "@reduxjs/toolkit";
export const mailSlice = createSlice({
name: "mail",
initialState: {
selectedMail: null,
sendMessageIsOpen: false,
},
reducers: {
selectMail: (state, action) => {
state.selectedMail = action.payload;
},
openSendMessage: (state) => {
state.sendMessageIsOpen = true;
},
closeSendMessage: (state) => {
state.sendMessageIsOpen = false;
},
},
});
export const {
selectMail,
openSendMessage,
closeSendMessage,
} = mailSlice.actions;
export const selectOpenMail = (state) => state.mail.selectedMail;
export const selectSendMessageIsOpen = (state) => state.mail.sendMessageIsOpen;
export default mailSlice.reducer;
请帮忙,因为我是 redux 的新手
【问题讨论】:
标签: javascript reactjs redux material-ui