如何input在进入DOM时将焦点设置为元素?
单击按钮时,将显示输入元素.如何将焦点设置为此元素?
class Component extends React.Component{
constructor(props) {
super(props);
this.state = {
showInput: false
}
}
render() {
return (
<div>
<div onClick={() => {
this.setState({showInput: true});
ReactDOM.findDOMNode(this.refs.myInput).focus() // <- NOT WORKING
}}>
Show Input
</div>
{
(this.state.showInput) ? (
<input
type="text"
ref="myInput"
/>
) : ""
}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
ReactDOM.findDOMNode(this.refs.myInput).focus()在状态更改后调用不起作用.同时更改状态更改中的styleor type属性也不起作用.
如何使用state属性react-redux来指定注入的数据react-meteor-data?
react组件的结构如下:
import React from "react";
import {createContainer} from "meteor/react-meteor-data";
import {connet} from "react-redux";
import {Data} from "./data.js"
class App extends React.Component {
render() {
return (
<div>
{JSON.stringify(this.props.profile)}
</div>
);
}
}
const mapStateToProps = state => ({
ID: state.dataId // ID gets assigned to props here
});
export default createContainer(
() => ({
profile: Data.findOne({_id: >>>ID<<<}) // ID is needed here
}),
connect(mapStateToProps)(App)
);
Run Code Online (Sandbox Code Playgroud)
非常感谢!
问题:为什么该colnames函数与管道操作符%>%和[选择器一起使用时会生成一个小标题?
示例:给定以下标题:
library(tidyverse)
x <- tribble(
~a, ~b,
1, 0,
0, 1
)
Run Code Online (Sandbox Code Playgroud)
问题:当与管道运算符和[选择器一起使用时,colnames 函数会生成一个 tibbe :
x %>% colnames(.)[1]
#> # A tibble: 2 x 1
#> a
#> <dbl>
#> 1 NA
#> 2 NA
Run Code Online (Sandbox Code Playgroud)
而我希望它生成一个向量,就好像没有使用管道运算符一样:
colnames(x)[1]
#> [1] "a"
Run Code Online (Sandbox Code Playgroud) 如何将在jsx文件中定义的react-components捆绑在index.js文件中?
以某种方式可以通过访问组件import module from "/module"; let C = module.Component;。
带有:
/module
index.js
Component.jsx
Run Code Online (Sandbox Code Playgroud)