我对React还是很陌生,经常遇到一些关于语法安静的麻烦。 以下代码给我错误:声明或声明应为ts(1128)
扫描互联网,我得出的结论是很可能缺少括号?!
import React, { Component } from 'react';
import AuthContext from './AuthContext';
// Then create a provider Component to update children Components once the user role changes
class AuthProvider extends Component {
constructor() {
super()
this.state = {
role: "none"
}
}
render() {
return (
<AuthContext.Provider value={{
state: this.state,
isAuthenticated: () => {
if (this.state.role == "kursleiter" || this.state.role == "admin") {
return true
}
return false},
setRole: (newRole) => this.setState({
role: newRole
})
}}>
{this.props.children}
</AuthContext.Provider>
)
}
}
export default AuthProvider
答案 0 :(得分:0)
您需要将代码提取到函数中,以便可以调用它们。示例:
GLint modelLoc = glGetUniformLocation(ourShader.Program, "model");
GLint viewLoc = glGetUniformLocation(ourShader.Program, "view");
GLint projLoc = glGetUniformLocation(ourShader.Program, "projection");
glm::mat4 projection = ... already known ...
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
glm::mat4 view = glm::mat4(1.0f);
// adjust to the layout of your scene
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -10.0f));
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
for(unsigned int i = 0; i < 25; i++)
{
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, cubePositions[i]);
// the same rotation rate but a different offset for each object
float angle = 20.0f * i;
angle += std::fmod(glfwGetTime() * 20.0f, 360.0f);
// choose x or y rotation axis
auto axis=(i%2) ? glm::vec3(1.0f, 0.0f, 0.0f) : glm::vec3(0.0f, 1.0f, 0.0f);
model = glm::rotate(model, glm::radians(angle), axis);
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glDrawArrays(GL_TRIANGLES, 0, 36);
}
现在,您可以使用:
const isAuthenticated = () => {
// ...
}
之前,您使用的是函数,但不是函数。因此,React导致您对预期语句的错误抛出。
答案 1 :(得分:0)
我的网站上超级愚蠢:文件名不匹配,仅此而已。