我有以下代码,我想将yreact组件的值传递给moveVertically关键帧。有可能这样做吗?
import React from 'react';
import styled, {keyframes} from 'styled-components';
const moveVertically = keyframes`
0% {
transform : translateY(0px)
}
100% {
transform : translateY(-1000px) //I need y here
}
`;
//I can access y in here via props but can't send it above
const BallAnimation = styled.g`
animation : ${moveVertically} ${props => props.time}s linear
`;
export default function CannonBall(props) {
const cannonBallStyle = {
fill: '#777',
stroke: '#444',
strokeWidth: '2px',
};
return (
<BallAnimation time …Run Code Online (Sandbox Code Playgroud) 我有一个函数需要递归地传递闭包参数
use std::cell::RefCell;
use std::rc::Rc;
pub struct TreeNode {
val: i32,
left: Option<Rc<RefCell<TreeNode>>>,
right: Option<Rc<RefCell<TreeNode>>>,
}
pub fn pre_order<F>(root: Option<Rc<RefCell<TreeNode>>>, f: F)
where
F: FnOnce(i32) -> (),
{
helper(&root, f);
fn helper<F>(root: &Option<Rc<RefCell<TreeNode>>>, f: F)
where
F: FnOnce(i32),
{
match root {
Some(node) => {
f(node.borrow().val);
helper(&node.borrow().left, f);
helper(&node.borrow().right, f);
}
None => return,
}
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用:
use std::cell::RefCell;
use std::rc::Rc;
pub struct TreeNode {
val: i32,
left: Option<Rc<RefCell<TreeNode>>>,
right: Option<Rc<RefCell<TreeNode>>>,
}
pub fn pre_order<F>(root: Option<Rc<RefCell<TreeNode>>>, f: F)
where …Run Code Online (Sandbox Code Playgroud)