You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to return Model instance from Selector instead of ref? #887
I'm new about this library and I'm trying to understand some basic concept/use cases.
The idea I made about this library is the ability to define a Model that can have custom method to collect the logic related to the data inside a single place.
Let's suppose I have a model of a book (the same that is in the README, reported below for clarity):
class Book extends Model {
toString() {
return `Book: ${this.name}`;
}
// Declare any static or instance methods you need.
}
Book.modelName = 'Book';
// Declare your related fields.
Book.fields = {
id: attr(), // non-relational field for any value; optional but highly recommended
name: attr(),
};
export default Book;
in my idea, in the component, I want to make something:
const bookSelector = createSelector(orm.Book);
function MyBookComponent({bookId}){
const book = useSelector(state => bookSelector(state, bookId))
return book.toString();
}
but this doesn't work because the bookSelector returns the ref of the book and not the instance model.
Activity
alessandro308 commentedon Jul 18, 2022
I proposed a solution here: #889