我的问题和标题一样.
假设我写了以下代码.
class TODOList extends Component {
render() {
const {todos, onClick} = this.props;
return (
<ul>
{todos.map(todo =>
<Todo
key={todo.id}
onClick={onClick}
{...todo}
/>
)}
</ul>
);
}
}
const mapStateToProps = (state) => {
return {
todos: state.todos
}
}
const mapDispatchToProps = (dispatch) => {
return {
onClick(data){
dispatch(complete(data))
}
}
}
export default connect(mapStateToProps,mapDispatchToProps)(TODOList);
Run Code Online (Sandbox Code Playgroud)
现在,在最后一行之后,此代码将导出TODOList组件,其状态为props.它不是包含状态,而是只是接收状态并将它们作为"道具",就像方法名称"mapStateToProps"解释的那样.
在Dan Abramov编写的媒体文章(https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)中,容器组件将数据作为状态处理,而表示属性作为道具处理.它不是一个将数据作为道具处理的表示组件吗?我坚持认为合适的容器应该像下面那样.
class CommentList extends React.Component {
this.state = { comments: [] };
componentDidMount() {
fetchSomeComments(comments =>
this.setState({ comments: comments …Run Code Online (Sandbox Code Playgroud) 我在Windows上下载了git,并安装了其他一些东西,包括git bash。
Although I didn't know why bash terminal has been included in the "git", it supported not only the functions for git, but other functions like mkdir, cp, mv, just like a real linux bash terminal.
Recently I came to know the WSL (Windows Subsystem for Linux), which makes bash terminal available in windows.
Is the git bash quite inferior to WSL in terms of functionality?
Does it contain some constraints that WSL doesn't have?
我在 django rest 框架中注意到序列化器和渲染器之间的区别时遇到了麻烦。
我认为序列化程序用于将 python 对象转换为 JSON(或其他数据格式)。但是渲染器,例如 JSONRenders,据说会做类似的事情,例如制作(渲染)JSON 对象!
你能告诉我这两者的区别吗?
问题的主要思想与标题相同 - 当您从 Android 中的 uri 获取文件的真实路径时,.getPath() 与光标之间有什么区别?
如果您没有理解我使用游标的意思,示例在此处。
private String getRealPathFromURI(Uri contentURI) {
String result;
Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
result = contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
result = cursor.getString(idx);
cursor.close();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
最常用的两种方式是这两种,但是使用游标似乎有点太复杂了,而您可以通过一种简单的方法 .getPath() 获得相同的结果。所以,我认为在某些情况下我应该使用光标肯定是有原因的,但我无法理解。
你能解释一下它会是什么吗?
我想使用字符串类。我还应该参与using namespace std;吗?
我以为#include <string>就足够了,但是在CLion中,只有这两个(命名空间或包含)之一不存在时,会出现一些错误。
使事情变得更复杂的是存在<string>或<strings.h>。有什么不同?
android ×1
c++ ×1
django ×1
git-bash ×1
include ×1
javascript ×1
namespaces ×1
react-redux ×1
reactjs ×1
redux ×1