Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F969559
README.md
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
README.md
View Options
#
Cosealious
Helper
for
using
REST
APIs
build
with
Sealious
in
the
web
,
with
React
hooks
##
Usage
###
Describe
a
collection
First
,
you
need
to
tell
Coselaious
what
is
the
structure
of
the
collections
on
the
back
-
end
.
```
ts
import
{
CollectionItem
,
CollectionClient
}
from
"@sealcode/cosealious"
;
const
MyCollectionFields
=
{
name
:
""
,
age
:
""
,
best_friend
:
""
// a reference to other collection
}
export
class
MyCollectionItem
extends
CollectionItem
<
typeof
MyCollectionFields
>
{
getInfo
()
{
return
{
collection_name
:
"my-collection"
,
fields
:
MyCollectionFields
,
writable_fields
:
Object
.
keys
(
MyCollectionFields
)
as
Array
<
keyof
typeof
MyCollectionFields
>,
fields_with_attachments
:
[
"best_friend"
]
as
Array
<
keyof
typeof
MyCollectionFields
>,
};
}
// you can extend the collection item class with your own methods, if you like
}
export
class
MyCollectionClient
extends
CollectionClient
<
typeof
MyCollectionFields
,
MyCollectionItem
>
{
collection_name
=
"my-collection"
;
item_constructor
=
MyCollectionItem
;
}
```
Then
you
can
use
it
in
a
component
:
```
ts
import
{
useCollection
}
from
"@sealcode/cosealious"
;
function
component
(){
const
[
myCollectionClient
,
items
,
client_params
]
=
useCollection
(
MyCollectionClient
,
{
filter
:
{
when
:
getDate
()
},
sort
:
{
when
:
"asc"
},
}
);
// ...
return
items
.
map
(
item
=>
<
div
>
entry
.
data
.
when
</
div
>);
}
```
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 23, 05:45 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
547696
Default Alt Text
README.md (1 KB)
Attached To
Mode
rCOS Cosealious
Attached
Detach File
Event Timeline
Log In to Comment