Next13 一周前发布,我正在尝试将 next12 应用程序迁移到 next13。我想尽可能多地使用服务器端组件,但我似乎无法使用
import { createContext } from 'react';
Run Code Online (Sandbox Code Playgroud)
在任何服务器组件中。
我收到此错误:
Server Error
Error:
You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
,----
1 | import { createContext } from 'react';
: ^^^^^^^^^^^^^
`----
Maybe one of these should be marked as a client entry with "use client":
Run Code Online (Sandbox Code Playgroud)
这里有其他选择吗?还是我必须诉诸道具钻探来获得服务器端渲染?
我正在尝试进行API调用(使用angular4),它在失败时重试,使用retryWhen.我希望它延迟500毫秒,然后再次重试.这可以通过以下代码实现:
loadSomething(): Observable<SomeInterface> {
return this.http.get(this.someEndpoint, commonHttpHeaders())
.retryWhen(errors => errors.delay(500));
}
Run Code Online (Sandbox Code Playgroud)
但这将永远尝试.我怎么限制它,比方说10次?
谢谢!
我正在编写使用routeLink的最简单的组件:
@Component({
selector: 'memorySnippet',
templateUrl: '<div class="memory-snippet-wrapper" *ngIf="memory"
[routerLink]="['MainPanel', 'MemoryPanel', {'id' : this.memory.id}]">',
directives: [CORE_DIRECTIVES, ROUTER_DIRECTIVES]
})
export class MemorySnippetComponent {
@Input() memory: Memory;
}
Run Code Online (Sandbox Code Playgroud)
我尝试测试此组件时会出现此问题.我添加路由器链接Karma的那一刻抱怨缺少提供者:
添加所有提供商后,Karma要求我得到这个:
beforeEachProviders(() => [
MemorySnippetComponent,
MEMORY_SERVICE_PROVIDERS,
ROUTER_PROVIDERS,
ApplicationRef
]);
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时,我得到了这个错误:
EXCEPTION:EXCEPTION:Token RouterPrimaryComponent实例化时出错!(RouterLink - > Router - > RouteRegistry - > Token RouterPrimaryComponent).
原始例外:未实现
ORIGINAL STACKTRACE:错误:未实现
我究竟做错了什么???Angular 2(2.0.0-beta.1)还没准备好用路由器指令测试组件吗?