types.Date is giving error. #1696
-
I have a model which has props:-
when i fill in values then i get this error:- |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @abhiram2600! It looks like the value you are trying to pass to const MyModel = types
.model("MyModel", {
comments: types.array(
types.model({
commentBy: types.string,
comment: types.string,
commentTimeStamp: types.Date
})
)
})
.preProcessSnapshot((snapshot) => ({
...snapshot,
comments: snapshot.comments.map((comment) => ({
...comment,
commentTimeStamp: comment.commentTimeStamp.seconds * 1000
}))
}));
const myModel = MyModel.create({
comments: [
{
comment: "abcs",
commentTimeStamp: { seconds: 1618557929, nanoseconds: 191000000 },
commentBy: "abhi"
}
]
});
console.log(myModel.comments[0].commentTimeStamp);
// Fri Apr 16 2021 09:25:29 GMT+0200 (Central European Summer Time)
|
Beta Was this translation helpful? Give feedback.
Hi @abhiram2600!
It looks like the value you are trying to pass to
commentTimeStamp
is an object with propertiesseconds
andnanoseconds
. You could e.g. add a custompreProcessSnapshot
to just take theseconds
property and multiply it with 1000 to get milliseconds, and MST will be happy.