我可以配置 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) 在我的 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这里没有填充正确的值吗?
如何在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){ - 不工作
这是我的代码,目前有效。它检测组件 - 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) 这是我的示例 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) {
"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) 这似乎是一个非常简单的问题,但花了最后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
有许多要检测的节点类型,即:
eslint网站解释了规则,但未提供所有可用的节点类型检测。
我找到了一个检测IfStatement的教程示例,但这没有获取我的if语句,因此想知道我是否有语法错误。
我正在运行此代码来启动 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) 如何编写泛型,以便结果采用提供给泛型的另一种类型的参数?
这是我的示例代码。
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) reactjs ×4
typescript ×4
javascript ×3
eslint ×2
next.js ×2
browserify ×1
docker ×1
ecmascript-6 ×1
gulp ×1
jenkins ×1
jsx ×1
node.js ×1
prettier ×1
sass ×1
storybook ×1
watchify ×1