由于我已经实现了服务器端渲染并使用来管理样式styled-components,因此我无法在Chrome开发工具中编辑样式。devtools中的样式变为斜体,并且没有复选框可以关闭/打开指定的样式。
它可以在Mozilla中正常运行。但是为什么不在Chrome中呢?任何想法为什么会发生?谢谢。
注意:它在生产中发生。
javascript css google-chrome google-chrome-devtools styled-components
我有一个选择器:
const someSelector = createSelector(
getUserIdsSelector,
(ids) => ids.map((id) => yetAnotherSelector(store, id),
); // ^^^^^ (yetAnotherSelector expects 2 args)
Run Code Online (Sandbox Code Playgroud)
这yetAnotherSelector是另一个选择器,它接受用户id - id并返回一些数据.
但是,既然如此createSelector,我就无法访问它(我不希望它作为一个函数,因为memoization不会工作).
有办法在某种程度上访问商店createSelector吗?或者有没有其他方法来处理它?
我有一个功能:
const someFunc = (store, id) => {
const data = userSelector(store, id);
// ^^^^^^^^^^^^ global selector
return data.map((user) => extendUserDataSelector(store, user));
// ^^^^^^^^^^^^^^^^^^^^ selector
}
Run Code Online (Sandbox Code Playgroud)
这样的功能正在杀死我的应用程序,导致所有内容重新渲染并让我疯狂.帮助赞赏.
我做了一些基本的自定义memoization:
import { isEqual } from 'lodash';
const memoizer = {};
const someFunc = (store, id) => { …Run Code Online (Sandbox Code Playgroud) 我有一个代码,负责裁剪图像并将其裁剪区域保存在div列表中。每个div代表每个裁剪的图像。但是问题是-我不希望它们太大,我希望它们具有fixed高度和宽度,例如max 100x100px。
具有有效图像裁剪功能的Codesandbox:https ://codesandbox.io/s/fast-frost-0b5tt 裁剪逻辑相关的代码:
const width = pos.w + "px";
const height = pos.h + "px";
const marginLeft = - pos.x + "px";
const marginTop = - pos.y + "px";
return (
<div
key={i}
style={{
width: width,
height: height,
backgroundSize: "400px 300px",
backgroundPosition: `top ${marginTop} left ${marginLeft}`,
backgroundImage: "url('https://boygeniusreport.files.wordpress.com/2016/11/puppy-dog.jpg?quality=98&strip=all&w=400')"
}}
/>
);
Run Code Online (Sandbox Code Playgroud)
您会看到图像裁剪效果很好,但是新创建的图像具有动态的高度和宽度。
问题:如何使这些新创建的div具有固定的宽度和高度,但又不破坏它?谢谢!
目的是使子代(裁剪的图像)具有固定的高度和宽度,但将背景图像保持在正确的位置。但似乎我太停顿了,不能自己做
正在调整服务器端渲染和谷歌云功能。在托管上部署了所有内容,发生了一些非常奇怪的事情。当我进入我的页面时,会出现https://accounts.google.com页面...
有一些很长的链接:
https://accounts.google.com/signin/v2/identifier?
service=ah&passive=true&continue=https%3A%2F%2Fappengine.google.com
%2F_ah%2Fconflogin%3Fcontinue%3Dhttps%3A%2F%2Fus-central1-treebase-
b21-d5.cloudfunctions.net%2Fssrapp%2F&flowName=GlifWebSignIn&flowEntry=
ServiceLogin&hl=en-GB
Run Code Online (Sandbox Code Playgroud)
什么可能导致这种情况?如何解决?谢谢!
index.js 负责 SSR 的文件:import React from 'react';
import { renderToString } from 'react-dom/server';
import express from 'express';
import App from './app/containers/App';
import functions from 'firebase-functions';
const app = express();
app.get('**', (req, res) => {
const html = renderToString(<App />);
res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
res.send(`
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app">${html}</div>
<div id="fb-root"></div>
<script type="text/javascript" src="/main.30e39d69fe1ce70d8983.js"></script>
</body>
</html>
`);
});
export …Run Code Online (Sandbox Code Playgroud) javascript firebase reactjs firebase-hosting google-cloud-functions
正在寻找多年,没有找到任何值得的东西.
当我使用flow时,我可以简单地说:
import { type FieldProps, FormProps } from 'redux-form';
Run Code Online (Sandbox Code Playgroud)
是否有类似(并且那么简单)的方法在typescript中正确设置道具到redux形式?
文档没有说什么关于打字稿,只有一个页面用于Flow打字.
但是,我发现我可以propTypes从redux-form 导入类似的东西:
import { reduxForm, propTypes } from 'redux-form'
Run Code Online (Sandbox Code Playgroud)
但是 - redux-form没有像propTypes导出的那样,所以docs有点不赞成.
链接:https://redux-form.com/7.2.1/docs/api/props.md/
提前感谢您提供任何帮助.
tl;dr class RegistrationForm extends React.PureComponent<any> {
what to drop here ^^^^^
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的案例。我想在每个午夜更新我的收藏。我正在使用node-schedule:
schedule.scheduleJob('0 0 * * *', () => {
Users.updateMany();
});
Run Code Online (Sandbox Code Playgroud)
我要做的就是遍历我的collection(Users)中的每个文档,如果User.created是false,我想将其转换为true。
在javascript中,它将是:
for (let user in Users) {
if (user.created === false) {
user.created = true;
}
}
Run Code Online (Sandbox Code Playgroud)
用猫鼬怎么做?谢谢!
在 redux saga 中,如果我们想处理多个 promise,我们可以使用all(相当于Promise.all):
yield all(
users.map((user) => call(signUser, user)),
);
function* signUser() {
yield call(someApi);
yield put(someSuccessAction);
}
Run Code Online (Sandbox Code Playgroud)
问题是,即使其中一个承诺(调用)失败,整个任务也会被取消。
我的目标是保持任务活着,即使其中一项承诺失败。
在纯 JS 中我可以用 来处理它Promise.allSettled,但是在 redux saga 中正确的方法是什么?
编辑:仍然没有找到任何合适的解决方案,即使我包装了yield allintry... catch块,即使其中一个调用失败,整个任务也会被取消。
大卫在他的回购中:
https://github.com/davideast/react-ssr-firebase-hosting
具有firebase功能的文件index.js在主根目录中,而不是在/functions目录中.
但是,如果我这样做并将我的index.js文件放到主根,如果我这样做firebase deploy --only functions,请在控制台中说:
i deploying functions
Error: functions\index.js does not exist, can't deploy Firebase Functions
Run Code Online (Sandbox Code Playgroud)
问:他怎么可能让它发挥作用?我怎么能这样做并从其他目录成功部署功能/functions?
谢谢
firebase.json
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"functions": {
"source": "/"
}
}
Run Code Online (Sandbox Code Playgroud) 我正面临另一个问题。
我使用 firebase db 来存储文本和 firebase 存储来存储文件。我的问题来了。
问:从数据库中获取特定元素时,如何从存储中获取正确的图像?
这是我的尝试:
const storageRef = firebase.storage().ref('companyImages/companyImage' + 123);
^^^^^^^^^^^^ I dont have access to id yet :(
const task = storageRef.put(companyImage);
task.on('state_changed', () => {
const percentage = (snap.bytesTransferred / snap.totalBytes) * 100;
// ^^^^^^^^^^^^ not sure if i even need this
}, (err) => {
console.log(err);
}, () => {
firebase.database().ref('offers').push(values);
^^^^^^^^^^^^^^^ now I could retrieve id from it with .key but its too late
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我首先要做的是上传图像,当它成功时,我开始将数据上传到数据库。 …
我在nodejs帮助下将pdf文件上传到服务器时遇到了麻烦。
我的代码:
app.post("/sendFile", function(req, res) {
var stream = fs.createWriteStream(path.join(__dirname, 'public', req.body.name + ".pdf"));
stream.once('open', function () {
stream.write(req.body.file);
stream.end();
});
});
Run Code Online (Sandbox Code Playgroud)
但是,正在上传的文件是Blob。Nodejs文档说该.write函数接受<string> | <Buffer> | <Uint8Array>第一个参数。会接受Blob吗?如果没有,我应该使用哪个其他功能将a正确上传Blob到服务器?
谢谢。
编辑:或者也许我应该Blob换成其他东西?
javascript ×10
reactjs ×6
firebase ×3
css ×2
node.js ×2
firebase-cli ×1
fs ×1
mongodb ×1
mongoose ×1
promise ×1
react-redux ×1
redux-form ×1
redux-saga ×1
reselect ×1
typescript ×1