所以我想从 Zod 数组中的对象的键中获取类型。该数组也嵌套在一个对象中,只是让事情变得更加困难。
这是我遇到的问题的抽象视图:
const obj = z.object({
nestedArray: z.array(z.object({ valueIWant: z.string() }))
})
// Should be of type z.ZodArray() now, but still is of type z.ZodObject
const arrayOfObjs = obj.pick({ nestedArray: true })
// Grab value in array through z.ZodArray().element
arrayOfObjs.element.pick({ valueIWant: true })
Run Code Online (Sandbox Code Playgroud)
在 Zod 中使用数组会发生什么:
// Type of z.ZodArray
const arr = z.array(z.object({ valueIWant: z.string() }))
const myValue = arr.element.pick({ valueIWant: true })
Run Code Online (Sandbox Code Playgroud)
这是我的实际问题:
我有一个返回以下对象的 API:
export const wordAPI = z.object({
words: z.array(
z.object({
id: z.string(),
word: …Run Code Online (Sandbox Code Playgroud) 出于某种原因,一些样式似乎不适用于 Netlify 上托管的生产版本。这似乎只发生在单个组件上。它是一个位于./layout/FormLayout.tsx(不知道这是否会改变任何东西)的包装器。这是包装器:
const FormLayout: React.FC<FormLayout> = ({ children, title, description }) => {
return (
<div className="w-screen mt-32 flex flex-col items-center justify-center">
<div className="p-6 flex flex-col items-center justify-center">
<h2 className="text-4xl font-semibold text-blue-400">
{title}
</h2>
{description && (
<h6 className="mt-4 text-md font-medium">{description}</h6>
)}
<div className="mt-12 w-max">{children}</div>
</div>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
它在这里使用:
const Register: React.FC<RegisterProps> = () => {
return (
<FormLayout title="Register" description="Register with your email.">
{/* form stuff. styles do work in here */}
</FormLayout>
)
} …Run Code Online (Sandbox Code Playgroud) 因此 a 拥有一个具有timer值的有状态父级。该计时器可由用户重置。我还有一个带有动画控制器的子有状态小部件。父级将timer值传递给子级以重置动画。这是一些代码:
class _ParentState extends State<Parent> {
int timer = 20;
void _userInput() {
setState(() {
timer = 20;
}
}
@override
Widget build(BuildContext context) {
return Child(
time: timer
);
}
}
Run Code Online (Sandbox Code Playgroud)
注意:为了简单起见,这是条带化的
因此,当我的用户触发该_userInput方法时,计时器值会改变,但孩子不会改变。这是我的完整子小部件:
class TimerProgress extends StatefulWidget {
TimerProgress({
Key key,
@required this.time,
@required this.onCompleted
}) : super(key: key);
final int time;
final Function onCompleted;
@override
_TimerProgressState createState() => _TimerProgressState();
}
class _TimerProgressState extends State<TimerProgress> with SingleTickerProviderStateMixin {
AnimationController _controller; …Run Code Online (Sandbox Code Playgroud) arrays ×1
css ×1
dart ×1
flutter ×1
javascript ×1
next.js ×1
reactjs ×1
tailwind-css ×1
trpc.io ×1
typescript ×1
zod ×1