我是 React 和 Redux 的新手,正如我们所知,对于那些具有状态的组件,最好使用类组件,我想问的问题是,是否建议对具有连接和交互的组件使用功能组件? Redux 存储,因为那些与存储交互的组件在本地没有状态。
我是React的新手,并且很了解setState在幕后的工作方式。因此,我想问一些问题。首先,setState是否总是异步的?如果不是在一般情况下是同步的。其次,它是如何通过Web API执行然后在回调队列中在setState中发生异步的?伙计们,如果有不清楚的地方,请告诉我。我真的很需要你的帮助。
我是JS的新手,正在尝试学习如何在JS中正确使用indexOf,也就是说,如果您看下面的代码:
var sandwiches = ['turkey', 'ham', 'turkey', 'tuna', 'pb&j', 'ham', 'turkey', 'tuna'];
var deduped = sandwiches.filter(function (sandwich, index) {
return sandwiches.indexOf(sandwich) === index;
});
// Logs ["turkey", "ham", "tuna", "pb&j"]
console.log(deduped);
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除重复项,但想问两个问题。首先,在这里返回sandwichs.indexOf(sandwich)=== index; 为什么我们需要使用“ == index;”。其次,由于indexOf返回索引,如0、1或2 ...那么为什么当我们console.log(deduped)时,我们得到的是名称数组而不是索引数组。希望你明白我的意思
我是React的新手,正在学习如何处理表单中的多个输入。这是代码:
class Login extends Component {
constructor () {
super();
this.state = {
email: '',
password: ''
};
this.handleChange = this.handleChange.bind(this);
}
handleChange (evt) {
// check it out: we get the evt.target.name (which will be either "email" or "password")
// and use it to target the key on our `state` object with the same name, using bracket syntax
this.setState({ [evt.target.name]: evt.target.value });
}
render () {
return (
<form>
<label>Email</label>
<input type="text" name="email" onChange={this.handleChange} />
<label>Password</label>
<input type="password" name="password" …Run Code Online (Sandbox Code Playgroud) 我是 React 新手,想在 React 路由器上添加光标:指针链接悬停在 React 中。我正在使用 CSS 模块,基本上一切都正确,但鼠标悬停时仍然没有出现指针。这是我正在使用的代码:
<Link className={styles.title} to="/">
<h2>
<i className="fa fa-sun-o "></i>
{title}
</h2>
</Link>
The code in CSS file
.title,
.title:hover,
.title:active,
.title:visited,
.title:focus {
text-decoration: none;
cursor: pointer;
color: blue;
}
Run Code Online (Sandbox Code Playgroud) 我是JS新手,遇到了以下代码:
let cache={};
function memoizedAddTo80(n) {
if (n in cache) {
return cache[n]
} else {
cache[n]= n+80;
return cache[n]
}
}
Run Code Online (Sandbox Code Playgroud)
问题是什么是cache [n] ?,我的意思是,为什么我们在缓存后使用[n]。是否cache [n]等于cache.n或?
我是 JS 新手,正在学习 Web API。让我有点困惑的是,如果 console.log 是浏览器提供的 Web Api 的一部分,如果是的话,那么为什么它不通过回调队列启动,我的意思是,据我所知,JS 在运行时发送了一些东西不属于要启动的Web Api。例如,dom、setTimeOut 是 Web api,浏览器不会自行启动它,而是发送到 Web api
我在 React 中学习 CSS 模块时遇到了媒体查询为何不起作用的困惑。这是代码:
Header.module.css 文件
.nav {
list-style: none;
display: flex;
justify-content: flex-end;
margin: 0;
padding: 0;
}
.link {
margin-left: 20px;
}
.navContainer {
display: flex;
align-items: center;
justify-content: flex-end;
}
.header {
background-color: red;
}
@media (max-width: 768px) {
.nav-container {
color: red;
}
}
Run Code Online (Sandbox Code Playgroud)
Header.js 文件:
import React from "react";
import styles from "./Header.module.css";
const header = ({ home, about, contact }) => { return (
<div className="row">
<div className="col-md-4">
<i className="fa fa-3x fa-github"></i>
</div> …Run Code Online (Sandbox Code Playgroud) 我是JS的新手,正在学习高阶函数及其优点。到目前为止,我所知道的是HOF允许创建泛型函数,我们可以将其重用于多个相关操作,我希望我是对的,为什么我们需要将函数作为参数传递或返回函数以使泛型函数成为函数。好的,如果我们要创建通用和可重用的函数,那么为什么我们需要将函数作为参数传递或返回一个函数。请大家帮助:(