我这里有两个功能。很明显,它们之间有很多重叠,我想创建一个父函数,下面的两个函数都将从其扩展。
function Home() {
const [state, dispatch] = useContext(NTTrackerContext);
const history = useHistory();
function pushhistory(url, callback) {
history.push(url);
callback();
}
function teamhome2_message() {
const info = message.error({
content: "Log in to access team data!",
});
};
function checklogin(callback) {
if (!state.user.authenticated)
pushhistory("/accounts/login", function(){teamhome2_message();});
else
callback();
}
# ...
Run Code Online (Sandbox Code Playgroud)
function APIHome() {
const [state, dispatch] = useContext(NTTrackerContext);
const history = useHistory();
function pushhistory(url, callback) {
history.push(url);
callback();
}
function apihome2_message() {
const info = message.error({
key: "apihome2",
content: "Log in to …
Run Code Online (Sandbox Code Playgroud)