小编Sar*_* UK的帖子

在 React 中 npm run build 后没有 service-worker.js 文件

运行后npm run devbuild 文件夹中没有 service-worker.js 文件。

我也在serviceWorker.register()index.js 中 进行了更改
,我也在这个项目中使用firebase。

这是package.json文件

{
  "name": "movie",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.20.0",
    "email-verifier": "^0.4.1",
    "firebase": "^7.24.0",
    "history": "^5.0.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-lottie": "^1.2.3",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini …
Run Code Online (Sandbox Code Playgroud)

firebase reactjs progressive-web-apps create-react-app

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

测试 Pressable 的按下状态

我有一个渲染 React NativePressable并使用pressed状态来改变显示的组件:

<Pressable testID="t">
  {({ pressed }) => <Text style={pressed ? pressedStyle : unPressedStyle }>{title}</Text>
<Pressable>
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我运行测试覆盖率报告时,pressed状态被跳过。即使我press在可按下的事件上触发事件,也会发生这种情况,例如:

const { getByTestID } = render(<PressableComponent />);
const pressable = getByTestID('t');
fireEvent.press(pressable);
Run Code Online (Sandbox Code Playgroud)

有没有办法pressed在测试期间触发状态,以便我可以测试该分支?

jestjs react-native react-testing-library

4
推荐指数
1
解决办法
332
查看次数

如何从顶点图表中删除图例、标签和所有数字

在此输入图像描述

我已经尽力了。如果有人能帮助我,那就太好了。我希望图表上的数字和图例消失

reactjs apexcharts

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

jsPDF , TypeError: pdf.fromHTML 不是 REACT 中的函数

我正在使用下一个代码使用 jsPDF 和一个简单的反应组件将 HTML 转换为 PDF。

import React from 'react';
import { renderToString } from 'react-dom/server';

import jsPDF from 'jspdf';

const styles = {
    fontFamily: 'sans-serif',
    textAlign: 'center',
};
const colstyle = {
    width: '30%',
};
const tableStyle = {
    width: '100%',
};

const Prints = () => (
    <div>
        <h3>Time & Materials Statement of Work (SOW)</h3>
        <h4>General Information</h4>
        <table id='tab_customers' class='table table-striped' style={tableStyle}>
            <colgroup>
                <col span='1' style={colstyle} />
                <col span='1' style={colstyle} />
            </colgroup>
            <thead>
                <tr class='warning'>
                    <th>SOW Creation Date</th> …
Run Code Online (Sandbox Code Playgroud)

jspdf reactjs

4
推荐指数
2
解决办法
4434
查看次数

您可以使用 Array.flatMap 在 Javascript 中返回 n 个选择 k 个组合吗?

例如,这是 5 选择 2:

    var array = [0,1,2,3,4];
    
    var result = array.flatMap(
        (v, i) => array.slice(i+1).map(w => [v, w]) 
    );
    
    console.log(result);
Run Code Online (Sandbox Code Playgroud)

我怎样才能使用这种方法做 5 选择 3?

javascript arrays probability

3
推荐指数
1
解决办法
166
查看次数

使用 JS 将数组转换为 JSON 对象

请帮助将数组转换为 JSON 对象

var array = [1, 2, 3, 4]; 
var arrayToString = JSON.stringify(Object.assign({}, array));
var stringToJsonObject = JSON.parse(arrayToString);
 
console.log(stringToJsonObject);
Run Code Online (Sandbox Code Playgroud)

我试试这个并得到:

{0: 1, 1: 2, 2: 3, 3: 4}
Run Code Online (Sandbox Code Playgroud)

预期结果

{place0: 1, place1: 2, place2: 3, place3: 4}
Run Code Online (Sandbox Code Playgroud)

javascript json

3
推荐指数
1
解决办法
342
查看次数

在Typescript中,如果设置了另一个可选属性,如何使属性成为必需的?

我不确定,在下面的要求中搜索什么。我正在使用以下类型的反应道具。

interface ComponentProps {
   message : string,
   minValue? : number,
   minValueValidationMessage? :string
}
Run Code Online (Sandbox Code Playgroud)

现在,我想让打字稿知道,如果minValue指定了,那么minValueValidationMessage也应该是必需的。

如果minValueValidationMessage指定,则minValue也应指定。

我有很多类似的组合,可以在任何排列和组合中发生。

typescript reactjs react-props

3
推荐指数
1
解决办法
871
查看次数

在参考滚动视图上反应本机错误,但可以工作

我需要滚动到平面列表的底部,所以我使用:

const scrollViewRef = useRef();


//my scroll view
<ScrollView
    ref={scrollViewRef}
    onContentSizeChange={() => {
        scrollViewRef.current.scrollToEnd({ animated: true });
    }}

Run Code Online (Sandbox Code Playgroud)

但我得到了这些错误:

在此输入图像描述

第一个是:

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<ScrollViewProps>): ScrollView', gave the following error.
    Type 'MutableRefObject<undefined>' is not assignable to type 'string | ((instance: ScrollView | null) => void) | RefObject<ScrollView> | null | undefined'.
      Type 'MutableRefObject<undefined>' is not assignable to type 'RefObject<ScrollView>'.
        Types of property 'current' are incompatible.
          Type 'undefined' is not assignable to type 'ScrollView | …
Run Code Online (Sandbox Code Playgroud)

javascript syntax-error typescript reactjs react-native

3
推荐指数
1
解决办法
4773
查看次数

如何使用 href 菜单项重定向到链接?

我正在使用MenuItemfrom material-ui,我想在单击菜单项时在新选项卡中打开链接。我用的是简单的: <MenuItem href="www.google.com" onClick={handleClose}> Google </MenuItem>

但什么也没发生。有人知道为什么吗?

href reactjs material-ui

3
推荐指数
1
解决办法
3451
查看次数

nodeJS中的重载函数调用

我有两个js文件add.js和testAdd.js

add.js

module.exports = function add(x,y) {
    console.log("------Starts x+y----");
    var a = x+y;
    console.log(a);
    return a;
}

module.exports = function add(x,y,z) {
    console.log("------Starts x+y+z----");
    var a = x+y+z;
    console.log(a);
    return a;
}
Run Code Online (Sandbox Code Playgroud)

testAdd.js

var add = require('./add');

add(300,100);

add(300,100,233);
Run Code Online (Sandbox Code Playgroud)

从testAdd我调用add.js中的add方法

发生的事情是函数调用总是转到add(x,y,z),因为函数没有根据参数进行选择(如java中所示).

我是nodeJS的新手.有人能帮我理解这个流程吗?并帮助我解决这个问题.提前致谢.

连接控制台o/p: -

在此输入图像描述

node.js

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

使用 useEffect 加载脚本

我正在使用 sdk,根据文档,我必须加载脚本:

 <body>
 <script>
    my sdk code
    my sdk code
    my sdk code
  </script>
  ..
  ..
  </body>
Run Code Online (Sandbox Code Playgroud)

你如何看到内部标签我有sdk代码。我正在使用 reactJs,我想在useEffect 钩子中加载这个脚本。
问题:sdk 的脚本如何运行,而不是在 body 标签中,而是在useEffect钩子中?

javascript reactjs use-effect

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

如何添加 moment.locale()

我有一个用英语进行的约会时刻。我正在尝试添加moment.locale法语约会,但它不起作用。应该创建一个变量来做到这一点?或者只是添加moment.locale()某个地方?

 <View style={{flex: 1}}>
        <Text style={{color: 'white', textAlign: 'center', marginTop:20}}>
              
              {moment(element.dateMatch).format('LLLL')}
            </Text>
        </View>
Run Code Online (Sandbox Code Playgroud)

使用此代码我可以得到英文日期。

javascript momentjs react-native

0
推荐指数
1
解决办法
8645
查看次数