我想向屏幕传递一个道具。当我尝试内联时,例如(props) => <Comp {...props} {...customProps} />我收到一条警告消息,我不应该将函数解析为该组件属性。好的。我以为我会为每个需要自定义道具的组件创建函数。它正在工作,但有更好的解决方案吗?这是我的组件:
export default function Loading() {
const [loggedIn, setLoggedIn] = React.useState(false);
const Stack = createStackNavigator();
const authService: AuthService = new AuthService();
const authProps: IAuthProps = {
authService
};
/**
* Bind neccessary props to the login component
* @param props Props
*/
function LoginWithProps(props) {
return <Login {...props} {...authProps} />;
}
/**
* Bin neccessary props to the registration component
* @param props Props
*/
function RegistrationWithProps(props) {
return <Registration {...props} {...authProps} />; …Run Code Online (Sandbox Code Playgroud) 所以我尝试设置一个 Mvc,用户可以在其中向服务器提交帖子。控制器应调用创建新帖子条目的服务。但是我在服务的方法调用中得到一个空指针异常。
我试图调试代码,它说postService自动装配的字段为空。堆栈跟踪显示相同。我试图删除所有代码,只使用服务中的布尔值来测试它,但这也不起作用。
这是 mvc 控制器
@RestController
@RequestMapping(value = "/post")
public class PostController {
@Autowired
private PostService postService;
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_OWNER')")
@PostMapping(value = "/")
private ResponseEntity<?> savePost(@RequestBody Post post, Principal principal){
//check if the body is invalid
if(post.getContent().equals("") || post.getTitle().equals("") ||post.getTitle() == null || post.getContent() == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
// here I tried to log it out
System.out.println(postService);
//update the database
return new ResponseEntity<>(postService.savePost(post,principal), HttpStatus.OK); //thats line 34
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 postService
@Service
public class PostService {
@Autowired …Run Code Online (Sandbox Code Playgroud) 我正在尝试存档一个函数正在返回一个 unicode 字符串,我想将它登录到控制台。但它要么显示有关函数的信息,要么不显示 unicode 字符串。
let test = () => "ÜTEST"
Js.log(test());
Js.log({j|$test()|j});
Run Code Online (Sandbox Code Playgroud)
第一个只返回"ÃTEST",第二个只返回有关函数本身的信息。
这是一个工作示例:https : //reasonml.github.io/en/try?rrjsx=true&reason=FAGwpgLgBBYM7QLxQBQEoqIHxQEQB2AVAUQGVDdhgApOAOhAHsBzFWBdNAbitoZZQBvAFYAfACTsI6UcIC+3
bucklescript ×1
java ×1
javascript ×1
ocaml ×1
react-native ×1
reactjs ×1
reason ×1
spring ×1
spring-boot ×1
spring-mvc ×1
unicode ×1