props mutation fix

This commit is contained in:
Igor Lobanov 2022-09-23 09:38:48 +02:00
parent b20b6ab83b
commit 585d789a1c
3 changed files with 12 additions and 6 deletions

View File

@ -216,7 +216,9 @@ type InitialState = {
topRatedMonthArticles?: Shout[]
}
export const useArticlesStore = ({ sortedArticles }: InitialState = {}) => {
export const useArticlesStore = (initialState: InitialState = {}) => {
const sortedArticles = [...(initialState.sortedArticles || [])]
addArticles(sortedArticles)
if (sortedArticles) {

View File

@ -96,8 +96,9 @@ type InitialState = {
authors?: Author[]
}
export const useAuthorsStore = ({ authors }: InitialState = {}) => {
addAuthors(authors || [])
export const useAuthorsStore = (initialState: InitialState = {}) => {
const authors = [...(initialState.authors || [])]
addAuthors(authors)
const getAuthorEntities = useStore(authorEntitiesStore)
const getSortedAuthors = useStore(sortedAuthorsStore)

View File

@ -116,9 +116,12 @@ type InitialState = {
sortBy?: TopicsSortBy
}
export const useTopicsStore = ({ topics, randomTopics, sortBy }: InitialState = {}) => {
if (sortBy) {
sortAllByStore.set(sortBy)
export const useTopicsStore = (initialState: InitialState = {}) => {
const topics = [...(initialState.topics || [])]
const randomTopics = [...(initialState.randomTopics || [])]
if (initialState.sortBy) {
sortAllByStore.set(initialState.sortBy)
}
addTopics(topics, randomTopics)