小编Emi*_*ron的帖子

在一个Vagrant框中的git pull之后随机"无法取消链接旧的'<file>'(Permission denied)"

我正在使用Homestead 5.0预先打包的Vagrant盒子工作,有时在一个git pull或之后git checkout,我得到

unable to unlink old '<file>' (Permission denied)
Run Code Online (Sandbox Code Playgroud)

重新启动我的盒子后,我可以正常拉或结账.我也尝试过git pull本地化,它完美无缺.

建立:

  • Mac OS Sierra
  • Virtual Box 5.1.14
  • 流浪汉1.9.1
  • Homestead 5.0

谁有这个问题?

git macos virtualbox vagrant homestead

10
推荐指数
1
解决办法
1495
查看次数

如何使用 EXTEND_ESLINT 环境变量扩展 CRA ESLint 规则

最近 Facebook 的 Create React App (CRA) 发布了一项新功能,允许您扩展他们的基本 ESLint 规则。

我们认识到,在某些情况下,需要进一步定制。现在可以通过将 EXTEND_ESLINT 环境变量设置为 true 来扩展基本 ESLint 配置。 设置你的编辑器

这是给出的示例,但没有详细信息,例如文件名或“共享配置”是什么。

{
    "eslintConfig": {
        "extends": ["react-app", "shared-config"],
        "rules": {
            "additional-rule": "warn"
        },
        "overrides": [
            {
                 "files": ["**/*.ts?(x)"],
                 "rules": {
                     "additional-typescript-only-rule": "warn"
                 }
             }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

该功能是通过添加环境变量启用的。

EXTEND_ESLINT=true
Run Code Online (Sandbox Code Playgroud)

但在文档页面上它也没有提供任何信息如何使用它 -高级配置

我已将他们的示例代码添加到我的构建文件中,.eslintrc.json但我收到了构建错误:

"错误:.eslintrc.json 中的 ESLint 配置无效:- 意外的顶级属性 "eslintConfig"。 "

有没有人让这个工作?该文件是否需要导出模块?

javascript npm eslint create-react-app

10
推荐指数
1
解决办法
3620
查看次数

在非 React 组件中使用钩子的替代方法是什么?

我是 React 新手,我有这个功能。

    import Axios from "axios";
    
    const UserService = {
        getUserRole: (access_token: string = "") => {
            return Axios({
                method: "get",
                url: "https://<url>/user/role",
                headers: {
                    "Authorization": `Bearer ${access_token}`
                }
            }).then((response) => {
                return response.data;
            }).catch((error) => {
                console.log(error);
            });
        }
    }

export default UserService
Run Code Online (Sandbox Code Playgroud)

经常被另一个组件使用getUserRole,例如

import UserService from "../../../services/authentication/userService";
import { useAuth } from "react-oidc-context";

...

const auth = useAuth();
UserService.getUserRole(auth.user?.access_token);
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我必须不断地传递access_tokenfrom useAuth。有什么方法可以useAuth在我的内部调用UserService,这样我就不必不断地access_token从我的组件传递?

javascript reactjs react-hooks

10
推荐指数
1
解决办法
5688
查看次数

嵌套三元语句

我想知道为什么这很奇怪.我知道区别在于分组,但相比之下它是否重要?

$i = 0;
foreach ($items as $item) {
   echo ($i == 0) ? 'first_row' : ($i == sizeof($feedbacks)-2) ? 'last_row' : 'none';
   $i++;
}
Run Code Online (Sandbox Code Playgroud)

回报

last_row
none
none
last_row
Run Code Online (Sandbox Code Playgroud)

$i = 0;
foreach ($items as $item) {
   echo ($i == 0) ? 'first_row' : (($i == sizeof($feedbacks)-2) ? 'last_row' : 'none');
   $i++;
}
Run Code Online (Sandbox Code Playgroud)

正确地返回它

first_row
none
none
last_row
Run Code Online (Sandbox Code Playgroud)

为什么会有区别?

php if-statement ternary-operator

9
推荐指数
2
解决办法
8989
查看次数

如何在Atom中安装shell命令以启用atom命令?

有人可以告诉我如何安装Atom的shell命令以atom在命令行中启用命令吗?

shell atom-editor

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

如何让 Visual Studio Code 导航到 React 组件的源文件?

考虑一个典型的 ReactJS 文件,例如:

import Popup from 'components/Popup/Popup';

// ...

<Popup
  trigger={
    <SVG src={pinIcon} className={pinClassName} />
  }
  content={pinTooltipText}
  position="bottom center"
  hideOnScroll
  className="popup-xl--hide"
/>
Run Code Online (Sandbox Code Playgroud)

在 VS Code 中,我想转到作为我的组件的文件,因此跳转到 components/Popup/Popup.xml 文件。使用转到定义:

转到 VS Code 中的定义

它让我进入进口申报。我无法跳转到那个文件。这很难管理,因为我们有数十个组件和属性在其中移动。能够通过转到每个定义快速“向下”导航组件堆栈将是令人麻木的真棒。

javascript reactjs visual-studio-code

9
推荐指数
1
解决办法
3575
查看次数

你如何为 getInitialProps 编写 Jest 测试?

static async getInitialProps({ query }) {
  let content;
  let alert;

  try {
    const first = query.first ? query.first : '';
    content = await getContent(first);
  } catch (error) {
    alert = 'There was an error loading data, please try again.';
    content = [];
  }

  return {
    content,
    alert,
  };
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为这个逻辑编写测试,但因为它是服务器端代码,我很难理解我如何为它编写测试,因为它在 instance() 中对我不可用。

谷歌没有向我展示这个方法,所以我想知道其他人是如何解决为 getInitial props 编写测试的。

javascript reactjs jestjs next.js

9
推荐指数
1
解决办法
3758
查看次数

如何在React函数组件中不使用useEffect钩子来获取数据?

我知道使用钩子时的传统方法是使用钩子获取数据useEffect。但是为什么我不能直接在功能组件中调用axios而不是hook然后设置数据呢。

基本上,我想问这样做有什么问题:

const [users, setUsers] = useState(null);
axios.get("some api call")
  .then(res => setUsers(res.data))
Run Code Online (Sandbox Code Playgroud)

在这里,我不使用useEffect会出什么问题吗?

javascript reactjs axios react-hooks use-effect

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

合并javascript中的两个对象,忽略未定义的值

我必须合并两个对象,但我不想将未定义的值分配给已定义的值。

A = { activity: 'purchased', count: undefined, time: '09:05:33' }
B = { activity: 'purchased', count: '51', time: undefined }
Run Code Online (Sandbox Code Playgroud)

当我尝试 Object.assign 时,未定义正在替换具有值的字段。

我想要的是

C = { activity: 'purchased', count: '51', time: '09:05:33' }
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

9
推荐指数
1
解决办法
4769
查看次数

如何在 React 的构建阶段禁用 ESLint

我正在使用 create-react-app 并为 eslint 配置了我的项目。下面是我的 .eslintrc 文件。

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint",
    "react-hooks"
  ],
  "extends": [
    "plugin:prettier/recommended",
    "airbnb-typescript-prettier",
    "prettier",
    "plugin:import/typescript"
  ],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "rules": {
    // Make prettier code formatting suggestions more verbose.
    "prettier/prettier": [
      "warn"
    ],
    "camelcase": "warn",
    "no-console": "error",
    "no-prototype-builtins": "warn",
    "arrow-body-style": "warn",
    "prefer-arrow-callback": "warn",
    "jsx-a11y/click-events-have-key-events": "warn",
    "jsx-a11y/no-noninteractive-element-interactions": "warn",
    // Disable <Fragment> => <> replacement. Feel free to change
    "react/jsx-fragments": "off",
    "react/destructuring-assignment": "warn",
    "react/no-unused-prop-types": "warn",
    //TODO: Remove this rule later
    "react/jsx-props-no-spreading": "off", …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs eslint create-react-app

9
推荐指数
1
解决办法
9169
查看次数