我们的 Next.js 应用程序的开发环境存在问题。
我们的 Javascript 堆不断耗尽内存。以下是具体的错误日志:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 0x10003ae75 node::Abort() [/usr/local/bin/node]
2: 0x10003b07f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x1001a7ae5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x100572ef2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
5: 0x10057c3f4 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
6: 0x10054e1e4 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
7: 0x10067fd99 v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
8: 0x1001c587d v8::String::Utf8Length() const [/usr/local/bin/node]
9: 0x10004e7b6 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
10: 0x2b9f4f0078a1
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我的useEffect()React 函数无法访问我的组件的状态变量。当用户放弃在我们的应用程序中创建列表并导航到另一个页面时,我试图创建一个日志。我正在使用useEffect() return复制componentWillUnmount()生命周期方法的方法。你能帮我吗?
let[progress, setProgress] = React.useState(0)
... user starts building their listing, causing progress to increment ...
console.log(`progress outside useEffect: ${progress}`)
useEffect(() => {
return () => logAbandonListing()
}, [])
const logAbandonListing = () => {
console.log(`progress inside: ${progress}`)
if (progress > 0) {
addToLog(userId)
}
}
Run Code Online (Sandbox Code Playgroud)
代码将达到addToLog(),导致记录此行为。
这就是当用户在他们的列表中输入一些内容,导致progress增加,然后离开页面时发生的情况。
useEffect()方法完美运行,并触发该logAbandonListing()功能console.log()(上面useEffect)记录了大于 0 的progress状态console.log()用于日志0 …我在尝试使用 MaterialUI 中的组件实现一些简单的事情时遇到了非常困难的情况Grid。具体来说,我想在一个布局行上将一个项目左对齐,将另一个项目右对齐。
我进行了广泛的搜索,但没有找到任何有效的解决方案。我尝试了很多建议,包括在组件中使用justifyContent和在 JSS 中,以及“推送”内容的技术。alignContentGridflex: 1
尝试将<Typography>元素放在左侧,将元素<FormGroup>放在右侧:
<Container>
<Grid container spacing={3}>
<Grid className={classes.rowLayout}>
// Goal is to align this to the LEFT
<Grid item xs={6}>
<Typography variant="h6" gutterBottom>Some Text</Typography>
</Grid>
// Goal is to align this to the RIGHT
<Grid item xs={3}>
<FormGroup>
// Simple `Switch` button goes here
</FormGroup>
</Grid>
</Grid>
</Grid>
</Container>
Run Code Online (Sandbox Code Playgroud)
MaterialUI JSS 样式:
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1, …Run Code Online (Sandbox Code Playgroud)