我想通过React Router将函数传递给子组件.我尝试了以下但它似乎不起作用.
class App extends Component {
constructor(props) {
super(props)
}
render() {
return (
<div className="App">
<div className="content">
<div className="centered-wrapper">
<Switch>
<Route exact path="/" component={Welcome} />
<Route path="/life" render={props => <Life sayHello = {this.sayHello()} />} />
</Switch>
</div>
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
我想sayHello()在Life组件中调用如下:
<div className="hello">{ this.props.sayHello() } I'm <Link to="/life">Marco</Link>! Welcome to my hood.</div>
Run Code Online (Sandbox Code Playgroud) 在完成一些验证后,如何移动到新页面React Router V4?我有这样的事情:
export class WelcomeForm extends Component {
handleSubmit = (e) => {
e.preventDefault()
if(this.validateForm())
// send to '/life'
}
render() {
return (
<form className="WelcomeForm" onSubmit={this.handleSubmit}>
<input className="minutes" type="number" value={this.state.minutes} onChange={ (e) => this.handleChanges(e, "minutes")}/>
</form>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我想将用户发送到另一条路线.我看了一下Redirect,但似乎它会删除我不想要的历史记录中的当前页面.
你能解释一下为什么结果是"int"吗?如果变量是一个字节,我希望它是"长"的.
public class Test{
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args){
byte b = 9;
printValue(b,b,b);
}
}
Run Code Online (Sandbox Code Playgroud) 我使用pg-promiseNode.js 模块创建了一个包含所有查询的单独文件。虽然对于其中的大多数我只是req, res在查询后使用,但对于一个我想返回一个值。这是行不通的。它返回undefined。
passportLogin: (email)=> {
db.one(`SELECT userid
FROM user`)
.then( result => {
return result;
})
.catch( error => {
return error;
});
}
Run Code Online (Sandbox Code Playgroud) 我最近使用 create-react-app 创建了一个网站。既然这不是一个网络应用程序,为什么我需要服务器来查看它?我尝试打开构建文件夹中的索引文件,但除非我从服务器提供它,否则它不起作用。
node.js single-page-application reactjs serve create-react-app
我的第一个组件如下:
const hellos = ['Hola', 'Salut', 'Hallo', 'Ciao', 'Ahoj', 'Annyeong-haseyo', 'Aloha', 'Howdy', 'Ni Hao', 'Konnichiwa']
export class Welcome extends Component {
constructor(props) {
super(props);
this.state = {
errors: []
};
}
sayHello = function() {
return hellos[Math.floor((Math.random()*hellos.length))];
}
render() {
return (
<div className="Welcome">
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够sayHello()从另一个组件调用。到目前为止,我所看到的所有答案都是关于父母与孩子的关系,但是在这种情况下,这两个部分没有任何关系。我想到了这样的事情,但没有完成工作:
import { Welcome } from './Welcome'
export const Life = () => (
<div className="Life">
<p>{ Welcome.sayHello() }</p>
</div>
)
Run Code Online (Sandbox Code Playgroud)
我想hellos在Life中打印一个随机的数组元素。
我遵循了文档,并使用此代码将 Google Analytics 添加到我的 React 应用程序:
import 'autotrack'
ga('create', 'MY CODE', 'auto');
ga('require', 'urlChangeTracker')
ga('send', 'pageview')
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Line 11: 'ga' is not defined no-undef
Line 12: 'ga' is not defined no-undef
Line 13: 'ga' is not defined no-undef
Run Code Online (Sandbox Code Playgroud)
我该如何解决?在此设置之后,我是否会获得当前使用原始 GA 片段获得的所有数据,并且实现代码拆分是否值得(我正在使用 Webpack)。
我想在每个字母后加上一个破折号,但我的正则表达式也要在末尾加一个破折号。如何改善我的正则表达式?
String outputS = dnaString.replaceAll("(.{1})", "$1-");
Run Code Online (Sandbox Code Playgroud) 我有一个create-react-appReact应用程序(使用 webpack生成),它使用 JSON 文件来检索文本内容和图像 URL 或相对路径。如果 JSON 中的内容可能会随时间发生变化,那么保存这些图像的最佳方法是什么:
src文件夹中。public文件夹中。我想在地图内创建条件渲染。数据取自具有以下结构的 JSON 文件:
export const products = [
{
"scores": {
"quality": 8,
"relevancy": {
"design": 3,
"code": 9,
"business": 5
}
},
"title": "AdCall: Bringing WebRTC to display ads",
"subtitle": "The first advertising banner with video calls",
"content": [
{
"type": "text",
"body": "AdCall is a concept for a new kind of online advertising banner. Using WebRTC, it allows for a click to call action with the aim of increasing conversions. It's built with a Node backend and deployed …Run Code Online (Sandbox Code Playgroud) reactjs ×7
node.js ×2
react-router ×2
webpack ×2
amazon-s3 ×1
express ×1
java ×1
json ×1
jsx ×1
pg-promise ×1
postgresql ×1
regex ×1
serve ×1