我正在尝试使用 D3 和 React 在时间轴上创建画笔交互,但我不明白为什么它不起作用。
useEffect()一切看起来都很好,但是当我在变量中设置状态时,index会创建一个无限循环。
const Timeline = () => {
const svgRef = useRef(null!);
const brushRef = useRef(null!);
const x = scaleLinear().domain([0, 1000]).range([10, 810]);
const [pos, setPos] = useState([]);
useEffect(() => {
const svg = select(svgRef.current);
svg.select('.x-axis')
.attr('transform', `translate(0,${110})`)
.call(axisBottom(x));
const brush = brushX()
.extent([
[10, 10],
[810, 110],
])
.on('start brush end', function () {
const nodeSelection = brushSelection(
select(brushRef.current).node(),
);
const index = nodeSelection.map(x.invert);
setPos(index);
});
console.log(pos);
select(brushRef.current).call(brush).call(brush.move, [0, 100].map(x));
}, [pos]);
return …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个使用 React(通过create-react-app)和 JSONServer 作为 API 的项目。
我有一个 Git 存储库,结构如下:
|-- client
|-- api
Run Code Online (Sandbox Code Playgroud)
为了在开发环境中工作,我启动这两个文件夹,npm start以便为 React 应用程序提供 http://localhost:3000,为 API 提供 http://localhost:3001。
这样(感谢 Axios)我可以连接到 http://localhost:3001/api 来检索我的内容
import axios from 'axios'
export default axios.create({
baseURL: 'http://localhost:3001/api'
})
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好。
现在我想将我的应用程序和 API 部署到 Heroku,这就是事情变得复杂的地方。
所以这是我的问题,如果能就最好的处理方法提供一些建议将会非常有帮助:
目前,我server.js在客户端文件夹的根目录中有一个文件,以及一个Procfile用于web: node server.js启动构建服务器的文件。然后我使用 Axios 从另一个 Heroku 应用程序(实际上是 …
我在GitHub上有一个存储库:
https://github.com/ludovicriffault/feed-tastic
我无法删除每个文件夹和子文件夹中的.DS_Store文件.我已经尝试了很多东西,比如文件.gitignore和Stackoverflow中的一些答案,但没有任何作用......
有什么想法解决这个问题?提前致谢!
我想显示一个像twitter和FB这样的时间格式(3小时前发布,2分钟前发布,等等......)
我试过这段代码没有成功:
function format_interval($timestamp, $granularity = 2) {
$units = array('1 year|@count years' => 31536000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
$output = '';
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$floor = floor($timestamp / $value);
$output .= ($output ? ' ' : '') . ($floor == 1 ? $key[0] : str_replace('@count', …Run Code Online (Sandbox Code Playgroud) reactjs ×2
axios ×1
brush ×1
codeigniter ×1
d3.js ×1
date ×1
file ×1
github ×1
gitignore ×1
heroku ×1
javascript ×1
json-server ×1
node.js ×1
react-hooks ×1
time ×1
timeago ×1