小编Ste*_*lin的帖子

如何在nextjs中使用scss而不使用css模块

我可以配置 webpack 以允许包含 scss。

注意:在静态 html 和 React 组件之间复制代码时,在原始 html 上使用 classNames 会更快,这就是我想这样做的原因。

如何在没有 css 模块和样式组件仅使用基本的 scss 和类名的情况下在 nextjs 中实现此功能?


import 'styles/MyComponent.scss';

const MyComponent = () => {
  return (
    <div className="someClass">
      stuff..
    </div>
  );
};

export default MyComponent;
Run Code Online (Sandbox Code Playgroud)

sass reactjs next.js

15
推荐指数
2
解决办法
4050
查看次数

为什么 Next.js 中未定义解构环境变量?

在我的 Next.js 应用程序中,我创建了一个.env包含名为 的变量的文件API_KEY

解构该值会产生undefined,如下所示:

const { API_KEY } = process.env; // = undefined
const key = process.env.API_KEY; // = 'value'
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下为什么process.env这里没有填充正确的值吗?

javascript environment-variables node.js next.js

8
推荐指数
1
解决办法
2747
查看次数

如何迭代嵌套对象并在jsx中渲染?

如何在jsx组件中渲染嵌套映射?

我需要做相当于javascript的(key in groupItem){}见下文.

class MyComponent extends React.Component {
    render () {    
        var options = this.props.options;
        return (            
            <div>
                {options.map(function(groupItem, key){ return (
                    /* 
                      Unexpected Token if using groupItem.map?
                      {groupItem.map(function(){return })}

                   */
                )})}
            </div>
        )
    }
}
Dropdown.defaultProps = {
   options:[{ 
      'groupX':{
          'apple':'lovely green apple',
          'orange':'juicy orange',
          'banana':'fat banana'
      }
   }]
}

JSON.stringify(groupItems) === {
    'groupX':{
        'apple':'lovely green apple',
        'orange':'juicy orange',
        'banana':'fat banana'
     }
}
Run Code Online (Sandbox Code Playgroud)

为什么这些不起作用?

groupItem.map - 不工作

Object.keys(groupItem).forEach(function(key){ - 不工作

javascript jsx ecmascript-6 reactjs

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

如何使用打字稿将多个引用传递给forwardRef

这是我的代码,目前有效。它检测组件 - Table 的宽度,然后在 Wrapper 上设置该宽度。

包装纸

import React from 'react';

type shapeWrapper = {
  filtered: string[]
};

type shapeState = {
  tableWidth: string,
  visibility: string
};

class Wrapper extends Component<shapeWrapper, shapeState> {
  private refParent = React.createRef<HTMLElement>();
  public ref = React.createRef<HTMLTableElement>();

// replace above with 
/*
public refTable = React.createRef<HTMLTableElement>(),
public refTds:HTMLTableElement[] = filtered.map(item => React.createRef<HTMLTableElement>());
public ref = {
  refTable,
  refTds
}
*/


  constructor(props: shapeWrapper) {
    super(props);
    this.setWrapperWidth = this.setWrapperWidth.bind(this);
    this.state = {
      tableWidth: '0',
      visibility: 'hidden'
    };
  } …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

6
推荐指数
0
解决办法
901
查看次数

react-hook-form - 控制器在第一次更改时未更新

这是我的示例 https://codesandbox.io/s/react-hook-form-b ​​asic-forked-4stdl?file=/src/index.js

它有 2 个输入示例 - 名字和姓氏。在firstName 中正确键入空格会显示错误。

在lastName 中输入空格(使用控制器)直到第二次按键后才会显示错误。它不会在第一次更改时触发。

不知道这是为什么。

import React, { FC } from "react";
import { useFormContext, useWatch, Controller } from "react-hook-form";

export interface Props {
  name: string;
  label?: string;
  defaultValue?: string;
}

const ControlledInput: FC<Props> = ({
  name,
  label: labelText = "",
  defaultValue = ""
}) => {
  const { register, control, errors } = useFormContext();

  const label = labelText || name;
  const value = useWatch({
    control,
    name,
    defaultValue
  });

  console.log(
    `ControlledInput() render(), name=${name}, …
Run Code Online (Sandbox Code Playgroud)

typescript react-hook-form

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

如何在 eslint 中使用 atom-typescript 或替代

Atom 软件包 - 已安装

  • 原子打字稿
  • 仅语言打字稿语法
  • 短绒
  • linter-eslint
  • linter-stylelint
  • linter-ui-default
  • 更漂亮的原子

更漂亮 - 设置:

  • ESLint 集成 = 选中
  • Stylelint 集成 = 选中
  • EditotConfig 集成 = 未选中

.eslintrc

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "impliedStrict": true,
      "experimentalObjectRestSpread": true
    }
  },
  "settings": {
    "react": {
      "pragma": "React",
      "version": "detect"
    },
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"],
        "paths": ["./"]
      },
      "babel-module": {}
    }
  },
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/react", …
Run Code Online (Sandbox Code Playgroud)

typescript eslint prettier

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

如何设置gulp将多个文件捆绑成一个?

这似乎是一个非常简单的问题,但花了最后3个小时来研究它,发现如果不使用watchify,每次保存新文件都会很慢.

这是我的目录树:

gulpfile.js
package.json

www/
  default.htm
     <script src="toBundleJsHere/file123.js"></script>

  toBundletheseJs/
    componentX/
       file1.js
    componentY/
       file2.js
    componentZ/
      file3.js

  toPutBundledJsHere/
      file123.js
Run Code Online (Sandbox Code Playgroud)

要求.在文件夹中每次创建或保存文件时,toBundleTheseJs/我希望将此文件重新分组toBundleJsHere/

我需要在package.json文件中包含哪些内容?

什么是我需要写入我的gulp文件的最小值?

这应该尽可能快,所以认为我应该使用browserify并观察.我想了解最小步骤,所以使用像jspm这样的包管理器这一点太过分了.

谢谢

javascript browserify bundling-and-minification gulp watchify

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

我在哪里可以查看所有的ast节点类型?

有许多要检测的节点类型,即:

  • 变量声明器
  • 功能表达
  • 成员表达
  • AssignmentExpression

eslint网站解释了规则,但未提供所有可用的节点类型检测。

我找到了一个检测IfStatement的教程示例,但这没有获取我的if语句,因此想知道我是否有语法错误。

abstract-syntax-tree eslint

4
推荐指数
3
解决办法
1014
查看次数

如何让 docker-compose 在 Windows 上的 docker 生成的 jenkins 管道中工作?

我正在运行此代码来启动 dockerized jenkins。这有效。

docker run -p 81:8080 -p 50000:50000 --name myjenkins --privileged -v %cd%/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins
Run Code Online (Sandbox Code Playgroud)

我使用 bitbucket、webhooks 成功签出 scm,并在每次推送时通过防火墙连接到本地 jenkins。之前的 Jenkinsfile 示例有效:

pipeline {
  agent any

  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我添加到我的 Jenkinsfile 中

pipeline {
  agent any
  stages {
      stage('Test') {
        steps {
          echo 'Testing...'
        }
      }
      stage('docker-compose') {
          steps {
             sh "./dockcompose.sh"
          }
      }
  }
  post {
     always {
        sh "./dockcompose-down.sh"
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

我有一个本地 docker-compose.yml 文件,我已经在本地进行了彻底的测试并且可以工作。在管道错误中我得到:

docker-compose: not …
Run Code Online (Sandbox Code Playgroud)

jenkins docker docker-compose

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

如何创建绑定故事书控件参数的通用打字稿函数

如何编写泛型,以便结果采用提供给泛型的另一种类型的参数?

这是我的示例代码。

import { Story } from '@storybook/react/types-6-0';

type TKeyAny = {
  [key: string]: string; // | 'other args values here...';
};

// this fails
export const bindargs = <A extends TKeyAny, T extends Story<A>>(args: A, Template: T): T => {
  const Comp = Template.bind({});
  Comp.args = args;
  return Comp;
};

export default bindargs;
Run Code Online (Sandbox Code Playgroud)

这可以工作,但它并不特定于传递给它的参数,这就是为什么我想要一个通用的:


// This works but I'd like this instead to be in a generic 
// export const bindargs = (args: TKeyAny, Template: Story<TKeyAny>): Story<TKeyAny> => { …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs typescript-generics storybook

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