我在使用油门时遇到问题。使用下面的代码,油门正常工作。但是,当我取消注释时出了点问题setPosition([e.clientX, e.clientY])。油门坏了,position不用等1秒,立即更新。
import React, { useState } from 'react'
import { throttle } from 'lodash'
export default () => {
const [position, setPosition] = useState([0, 0])
const [x, y] = position
const handleMouseMoveThrottle = throttle(e => {
console.log(e.clientX, e.clientY)
// setPosition([e.clientX, e.clientY])
}, 1000)
const handleMouseMove = e => {
e.persist()
handleMouseMoveThrottle(e)
}
return (
<div
style={{ width: 300, height: 300, border: 'solid 1px black' }}
onMouseMove={handleMouseMove}
>
<div>
Position: {x}, {y}
</div>
</div>
)
} …Run Code Online (Sandbox Code Playgroud) 这是我目前的网址:
http://myhost/main?my_id=1,3
Run Code Online (Sandbox Code Playgroud)
如何在CodeIgniter中获取此URL,它是否包含在"my_id"中?
注意:
我的意思是echo $url,它显示如下:http://myhost/main?my_id=1,3
你可以在这里看到我所做的事情。
import "babel-polyfill";
import React from "react";
import ReactDOM from "react-dom";
const asyncFunc = () => {
return new Promise(resolve => {
setTimeout(resolve("Gotcha!!!"), 10000);
});
};
class App extends React.Component {
state = {
text: "Fetching..."
};
componentDidMount = async () => {
const text = await asyncFunc();
this.setState({ text });
};
render() {
return <div className="App">{this.state.text}</div>;
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序应首先显示,然后在 10 秒后Fetching...显示。Gotcha!!!但是,它不起作用。我有什么错?