严格的相等运算符将告诉您两个对象类型是否相等.但是,有没有办法判断两个对象是否相等,就像 Java中的哈希码值一样?
Stack Overflow问题JavaScript中是否有任何类型的hashCode函数?类似于这个问题,但需要更多的学术答案.上面的场景说明了为什么需要有一个,我想知道是否有任何等效的解决方案.
这是这个问题的后续问题,最接近我的问题:
我正在创建一个小型 React.js 应用程序来研究该库。我收到此警告:
超出最大更新深度。当组件在 useEffect 中调用 setState 时会发生这种情况,但 useEffect 要么没有依赖项数组,要么依赖项之一在每次渲染时发生变化。
我有一个功能组件,其中有以下代码:
const propertiesMap2 = new Map([ //There is also propertiesMap1 which has the same structure
["TITLE4",
{
propertyValues: {
myProperty10 : "myVal1",
myProperty11 : "myVal2",
myProperty12 : "myVal3",
},
isOpen: true
}
],
["TITLE5",
{
propertyValues: {
myProperty13 : "myVal4",
myProperty14 : "myVal5",
myProperty15 : "myVal6",
},
isOpen: true
}
],
["TITLE6",
{
propertyValues:{
myProperty16 : "myVal7",
myProperty17 : "myVal8",
myProperty18 : "myVal9",
},
isOpen: true
} …Run Code Online (Sandbox Code Playgroud) 新的React API包括useEffect(),其第二个参数采用Object哪个React差异来查看组件是否已更新。
例如
useEffect(
() => {
const subscription = props.source.subscribe();
return () => {
subscription.unsubscribe();
};
},
[props.source],
);
Run Code Online (Sandbox Code Playgroud)
[props.source]论点在哪里。
我的问题是:我可以定义一个自定义函数来运行以检查道具是否已更改吗?
我有一个自定义对象,React似乎无法告诉它何时已更改。
我的 kotlin 应用程序中有一个端点,如下所示:
either.eager<String, Unit> {
val sessionAndCookieUser = commonAuth.decryptCookieGetUser(getCookie(context), ::userTransform).bind()
val user = sessionAndCookieUser.session.user
val ctx = Ctx(ds, SystemSession, conf)
val dbUser = getUserEither(ctx, user.id).bind()
val signatureAlgorithm = SignatureAlgorithm.HS256
val signingKey = SecretKeySpec(conf.get(ZendeskJWTSecret).toByteArray(), signatureAlgorithm.jcaName)
val iat = Date(System.currentTimeMillis())
val exp = Date(System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000)
val token = Jwts.builder()
.claim("name", dbUser.name)
.claim("email", dbUser.email)
.setIssuer(conf.get(StreamAppName))
.setIssuedAt(iat)
.setExpiration(exp)
.signWith(signingKey, signatureAlgorithm)
.compact()
context.setResponseCode(StatusCode.OK)
.setResponseType("application/json")
.send(jsonObject("token" to token).toString())
}.mapLeft {
context.setResponseCode(StatusCode.UNAUTHORIZED)
}
Run Code Online (Sandbox Code Playgroud)
我正在设置一个响应,jsonObject如果用户已通过身份验证或UNAUTHORIZED …
javascript ×3
reactjs ×3
equals ×1
fetch ×1
hashcode ×1
jwt ×1
listview ×1
object ×1
react-hooks ×1
react-native ×1