小编Vel*_*o89的帖子

React Router Dom - v6 - useBlocker

由于https://github.com/remix-run/react-router/issues/8139已完成并且我们进入useBlocker了 v6,有人让它工作吗?

这是我到目前为止所得到的,几乎我陷入了我完全不明白的错误

在 App.js 中我有我的BrowserRouter并且所有东西都包含在里面

我还使用了实施者要点中的示例(我复制粘贴)

import * as React from "react";
import { useBeforeUnload, unstable_useBlocker as useBlocker } from "react-router-dom";

function usePrompt(message, { beforeUnload } = {}) {

let blocker = useBlocker(
  React.useCallback(
     () => (typeof message === "string" ? !window.confirm(message) : false),
  [message]
  )
);
let prevState = React.useRef(blocker.state);

React.useEffect(() => {
    if (blocker.state === "blocked") {
    blocker.reset();
  }
  prevState.current = blocker.state;
}, [blocker]);

useBeforeUnload(
     React.useCallback(
       (event) => {
         if (beforeUnload …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router-dom react-hooks

8
推荐指数
2
解决办法
3万
查看次数

运行总计 - 日期差异

这就是表格的样子:

create table IncomeTest (SubjectId int, Date_Value date, debit number, credit number);

insert into IncomeTest values (1, '7-SEP-2017', 11000, 0);
insert into IncomeTest values (1, '7-DEC-2017', 6000, 0);
insert into IncomeTest values (1, '9-JAN-2018', 0, 16110);
insert into IncomeTest values (1, '9-JUL-2018', 0, 619.6);
insert into IncomeTest values (1, '23-JUL-2018', 0, 270.4);

commit;
Run Code Online (Sandbox Code Playgroud)

借方代表现金,贷方代表现金.插入表后,您将获得以下数据:

SubjectID | Date_value | Debit |  Credit 
    1       9/7/2017     11000         0
    1       12/7/2017     6000         0
    1       1/9/2018         0   16110.0
    1       7/9/2018         0     619.6
    1       7/23/2018        0 …
Run Code Online (Sandbox Code Playgroud)

sql oracle running-total

6
推荐指数
1
解决办法
109
查看次数

React - 在渲染之前等待承诺

我无法弄清楚这一点,如果你能指出我正确的方向。在我的 NavMenu.js 我有登录(两个输入和一个提交按钮,我调用handleSubmit()

handleSubmit()我检查用户登录凭据时效果很好,但在我确认登录后,我继续执行下一次获取以检查用户角色(并返回承诺)和应用程序中的可见性

Helper.js

function getAllRoles(formName, sessionVarName) {

    var roleData = [];
    var roleId = sessionStorage.getItem('UserLoggedRoleId');

    fetch('api/User/GetUserRole/', {
    'method': 'POST',
    headers: {
        'Accept': 'application/json, text/plain, */*',
        'Content-Type': 'application/json'
    },
    'body':
        JSON.stringify({
            'roleId': roleId,
            'formName': formName
        })
    }).then(roleResponse => roleResponse.json())
    .then(data => {
        sessionStorage.setItem(sessionVarName, JSON.stringify(data));
        roleData = data;
    });

  var result = Promise.resolve(roleData)

  return result;
}

function checkRoleVisibility(userRoles, role) {} <-- return true or false

export {
  getAllRoles ,
  checkRoleVisibility   
};
Run Code Online (Sandbox Code Playgroud)

在 NavMenu.js 中

import { getAllRoles, …
Run Code Online (Sandbox Code Playgroud)

render async-await reactjs

5
推荐指数
1
解决办法
2万
查看次数

SQL Server - 按外观替换字符串

有一个小问题……这是测试数据

CREATE TABLE #TestReplace (
    Description NVARCHAR(500)
    ,ParamValue1 INT
    ,ParamValue2 INT
    ,ParamValue3 INT
    );

INSERT INTO #TestReplace (Description)
VALUES ('This sentence has no parameteres, and it should be shown like this');

INSERT INTO #TestReplace (
    Description
    ,ParamValue1
    )
VALUES (
    'This sentence has only one parametere, and it should be shown right here {param} with rest of text'
    ,100
    );

INSERT INTO #TestReplace (
    Description
    ,ParamValue1
    ,ParamValue2
    )
VALUES (
    'This sentence has two parameteres, one here {param} and one …
Run Code Online (Sandbox Code Playgroud)

sql sql-server replace

5
推荐指数
1
解决办法
91
查看次数