嘿stackoverflowers,
removeEventListener()当我不使用throttle()lodash时工作.
window.addEventListener('scroll', this.checkVisible, 1000, false);
window.removeEventListener('scroll', this.checkVisible, 1000, false);
Run Code Online (Sandbox Code Playgroud)
(我绑定了构造函数中的方法)
不幸的是,throttle(this.checkVisible)功能缠绕它 - 不起作用.我认为这是因为当尝试删除监听器时,throttle()会生成新的实例,也许我应该全局绑定它.怎么样(如果是这样的话)?
import React from 'react';
import throttle from 'lodash.throttle';
class About extends React.Component {
constructor(props) {
super(props);
this.checkVisible = this.checkVisible.bind(this);
}
componentDidMount() {
window.addEventListener('scroll', throttle(this.checkVisible, 1000), false);
}
checkVisible() {
if (window.scrollY > 450) {
// do something
window.removeEventListener('scroll', throttle(this.checkVisible, 1000),
false);
}
}
render() {
return (
<section id="about"> something
</section>
);
}
}
export default About;
Run Code Online (Sandbox Code Playgroud)
谢谢,善意的人!
React-admin的Resource组件将nameprop值映射到一个端点。
例如从访问数据。http://example.com/abc,您的Resource组件如下所示:
<Resource name='abc'/>
我要访问什么资源http://example.com/abc/def?这<Resource name='abc/def'/>甚至不调用该dataProvider函数。
我不想以如下丑陋的解决方案结束:
// App.js
<Resource name='def'/>
Run Code Online (Sandbox Code Playgroud)
// dataProvider.js
if (resource==='def') {
url = 'abc/def'
}
Run Code Online (Sandbox Code Playgroud)
资源名称是否必须始终没有/?有骇客吗?
我想让埃米特帮我解决这个问题:
const str = 'lorem5|TAB'; --> const str = 'Lorem ipsum dolor sit amet.';
Run Code Online (Sandbox Code Playgroud)
|光标位置
TAB点击选项卡
在 VSCode 中可以吗?它仅对我有用jsx和html。
我在这里有一个高阶sorta函数.
虽然这按预期工作:
var square = (a) => a * a;
var callAndLog = (func) => {
return function () {
var res = func.apply(undefined, arguments);
console.log("Result is: " + res);
return res;
}
};
var squareAndLog = callAndLog(square);
squareAndLog(5); // Result is 25
Run Code Online (Sandbox Code Playgroud)
这里,当我返回一个箭头功能时,它不起作用:
var square = (a) => a * a;
var callAndLog = (func) => {
return (() => {
var res = func.apply(undefined, arguments);
console.log("Result is: " + res);
return res;
})
};
var squareAndLog = callAndLog(square); …Run Code Online (Sandbox Code Playgroud) javascript higher-order-functions ecmascript-6 arrow-functions
我使用了这个教程:https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/environment-variables.md
我遵循的步骤:
1)安装dotenv@4.0.0
2)在根文件夹中创建两个文件:".env.development"和".env.production"
3)"按照他们的设置说明"(dotenv npm docs上的示例)
在gatsby-config.js:
const fs = require('fs');
const dotenv = require('dotenv');
const envConfig =
dotenv.parse(fs.readFileSync(`.env.${process.env.NODE_ENV}`));
for (var k in envConfig) {
process.env[k] = envConfig[k];
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我跑步时gatsby develop,NODE_ENV尚未设定:
error Could not load gatsby-config
Error: ENOENT: no such file or directory, open 'E:\Front-End Projects\Gatsby\sebhewelt.com\.env.undefined'
Run Code Online (Sandbox Code Playgroud)
它在我手动设置时有效:
dotenv.parse(fs.readFileSync(`.env.development`));
Run Code Online (Sandbox Code Playgroud)
我需要gatsby-config中的环境变量,因为我将敏感数据放在这个文件中:
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: envConfig.CONTENTFUL_SPACE_ID,
accessToken: envConfig.CONTENTFUL_ACCESS_TOKEN
}
}
Run Code Online (Sandbox Code Playgroud)
如何使它工作?
PS:附加问题 - 因为这让我想到,我知道我不应该在github上放置密码和令牌,但是当从github构建netlify时,还有其他安全方法吗?
我正在浏览 Gatsby 示例入门博客,这是 Markdown 博客文章之一:
我认为作者不会像date: "2015-05-01T22:12:03.284Z"每次发帖一样在前面硬输入一个字符串。
这是vim的功能吗?如何在保存文件时自动向 Gatsby 的 Markdown 文件添加时间戳?
帮助表示赞赏:)
我正试着用Hugo ssg使用Netlify CMS.
我用:
netlify-cms@1.0
hugo@0.29
Run Code Online (Sandbox Code Playgroud)
我有一个简单的netlify-cms config.yml,有两个集合:帖子和作者.
backend:
name: github
repo: sebhewelt/atlas
branch: master
display_url: https://mypage.com
publish_mode: editorial_workflow
media_folder: "static/uploads"
public_folder: "/uploads"
collections:
- label: "Posts"
name: "post"
folder: "content"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" , format: "YYYY-MM-DD hh:mma"}
- { label: "Body", name: "body", widget: "markdown" }
- label: "Authors"
name: "author"
folder: "data"
create: true
fields:
- {label: "Name", …Run Code Online (Sandbox Code Playgroud) javascript ×4
gatsby ×2
contentful ×1
ecmascript-6 ×1
emmet ×1
events ×1
ide ×1
markdown ×1
netlify ×1
netlify-cms ×1
node.js ×1
react-admin ×1
reactjs ×1