编辑:下面的答案
我在youtube上都遵循了这两个教程(目前没有太多),但它们都不适用于我,它在index.js中向Provider发送了这个错误:
元素类型无效:期望一个字符串(用于内置组件)或一个类/函数(用于复合组件)但得到:object.
我的代码Context.js文件:
import React from 'react'
export const Context = React.createContext();
Run Code Online (Sandbox Code Playgroud)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloProvider } from 'react-apollo';
import { Context } from './Context'
const client = new ApolloClient({
link: new HttpLink({ uri: process.env.API_URL }),
cache: …Run Code Online (Sandbox Code Playgroud) 背景:我的网站上的Cookie格式错误(来自我的会员页面之一),出现400个错误(空白的400页响应)。我已经编写了删除Cookie的代码,但是我的一些客户仍然收到错误,因为它在其缓存中。一旦他们清除了缓存,问题就解决了。
只需忽略400错误,即可在我的.NET代码库中共同解决此问题,我想在Express JS中也做同样的事情。
问:我想表达对400个错误(通常是由有缺陷的Cookie引起)的所有cookie的忽略,或者至少一起忽略该错误。有什么办法吗?
我的ClearDefectiveCookies函数可供参考(功能正常)
const clearDefectiveCookies = (req, res, next) => {
const cookies = req.cookies;
const defectiveCookies = Object.keys(cookies).filter(key => typeof cookies[key] === 'string' && (cookies[key].charAt(0) === '='));
if (defectiveCookies.length > 0) {
defectiveCookies.forEach(defectiveCookie => {
res.clearCookie(defectiveCookie);
});
}
next();
};
Run Code Online (Sandbox Code Playgroud)
有问题的Cookie供参考
名称:xyz_123和值:=NaN=xyz=123
javascript cookies session-cookies express http-status-code-400
我想知道如何将 redux sagas 与 React hooks 结合使用,redux 是如何实现的,是否有任何独特的用例需要了解?
我应该使用常规的反应调度吗?
这种情况发生在多个命令变体中.
基本上......
首先我运行容器:docker run -it --publish 8080:8080 --name app_in_docker node:latest
然后我在几秒钟之后在下一行中得到这个响应:
>
这使得看起来我在容器中,即使命令行通常看起来像:
root@bcb5705c09c1:/#当我在容器中时.我输入的任何内容都>表明了这一点:
ReferenceError: <command> is not defined
at repl:1:1
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:440:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:279:10)
at REPLServer.Interface._line (readline.js:626:8)
Run Code Online (Sandbox Code Playgroud)
我已经使用了诸如ls,cd,exit,help, - help,WORKDIR,docker,error等命令而没有任何成功,我收到相同的消息.
然后我关闭docker quickstart终端(我正在使用windows和virtualbox在后台运行)并重新打开终端.我现在可以使用以下docker exec -it <container_name/id> bash命令进入容器:
命令行现在看起来应该如下:root@bcb5705c09c1:/#
第二个与半相关的问题,如果你能提供帮助!如何在计算机中指定音量路径?我没有成功地合并卷如此:docker run -it -v /c/app:/usr/src/app --publish 8080:8080 --name app_in_docker node:latest尝试连接到C:\ …
我有一个粘性栏,我想让用户通过在右侧有一个 X 来关闭它position: absolute。但是,当点击它时,它也会触发“分享到 Facebook”事件。我如何阻止这种情况发生?
JS文件
return (
<div
className={'ShareBar'}
onClick={()=>console.log('sharing')}>
<span className={'ShareCTA'}>
{facebook.svg} Share on Facebook ™
<span
className={'CloseButton'}
handleClick={function (e) { e.stopPropagation()/*attempted fix*/; console.log('closing'); return; }}>
X
</span>
</span>
</div>
);
Run Code Online (Sandbox Code Playgroud)
CSS 文件(它是一个 sass 文件,所以没有分号之类的东西
.ShareBar
position fixed
bottom 0
z-index 9999
display flex
justify-content flex-end
align-items center
height 48px
cursor pointer
width 100%
...
.ShareCTA
width 100%
position relative
display flex
justify-content center
align-items center
font-size 20px
...
svg
height 20px
.CloseButton
position absolute
z-index …Run Code Online (Sandbox Code Playgroud) 据我了解,onFocus单击输入框时应调用它,而onBlur当其他内容成为焦点时应调用它。
我的意图是:我想调用一个函数,当单击激活该函数时,它将.concat成为focuse中输入框的消息字符串,但是我无法使用onFocus或onBlur工作。
从我发现的搜索范围来看,这应该可以解决问题,但事实并非如此。
import React, { Component } from 'react'
class SocialPost extends Component {
state = {
message: this.props.socialPost.message,
focus: false
}
_onBlur() {
setTimeout(() => {
if (this.state.focus) {
this.setState({
focus: false,
});
}
}, 0);
}
_onFocus() {
if (!this.state.focus) {
this.setState({
focus: true,
});
}
}
render() {
return (
<div className='...'>
<div className='...'>
...
<input
onFocus={this._onFocus()}
onBlur={this._onBlur()}
type='text'
value={this.state.message}
onChange={...}/>
...
</div>
</div>
) …Run Code Online (Sandbox Code Playgroud) 我创建了一个新的云运行服务,设置为每秒 50 个最大请求(并发),但在生产中它一直徘徊在最大 2-3 个请求/秒/容器。我知道 cloud run 的目标是将 CPU 保持在 60% 左右,但我已经将其从 1 个 vCPU 增加到 4 个 vCPU,但我仍然没有看到我现在期望的 0.75 req/s 负载所需的 1 个容器。我尝试了“始终分配”CPU,但它并没有减少活动实例数。
到底是怎么回事?有什么办法可以让它坚持我设定的最大值吗?如果继续这样扩展,将会额外花费数百美元,因为我什至还没有打开所有请求。
替代问题:由于成本仅在请求分配期间产生,也许我不需要付费,并且活动容器的数量并不重要?
PS:这是一个无头抓取服务,因此它将运行无头 chrome,这需要大量的 CPU 才能启动,但每个额外的选项卡都不会大幅增加 CPU 要求。
PSS:此外,任何有关保持容器数量较低的建议建议都值得赞赏:我添加了最小活动实例 1,但这就是我考虑的全部内容。
javascript ×3
reactjs ×3
command-line ×1
concurrency ×1
containers ×1
cookies ×1
css ×1
docker ×1
express ×1
html ×1
onblur ×1
onchange ×1
react-16 ×1
react-hooks ×1
redux ×1
redux-saga ×1
volumes ×1