score:2
Accepted answer
What you need might be a Search
store which keeps track of following information:
- Query params (offset, limit, etc.)
- Query results (results of the last search)
- (Optional) Query state (isLoading)
Then to avoid storing articles in 2 places, the query results should not use Article
model, but reference to Article
model. Anytime you query, the actual result will be saved in existing store ArticleStore
, and Search
only holds references:
import { types, getParent, flow } from 'mobx-state-tree'
const Search = types.model({
params: // your own params info
results: types.array(types.reference(Article))
}).views(self => ({
get parent() {
return getParent(self) // get root node to visit ArticleStore
}
})).actions(self => ({
search: flow(function*(params) {
this.params = params // save query params
const result = yield searchByQuery(query) // your query here
this.parent.articleStore.saveArticles(result) // save result to ArticleStore
this.results = getArticleIds(result) // extract ids here for references
})
}))
Hope it's what you are looking for.
Source: stackoverflow.com
Related Query
- Structure: How to represent a search input, search query, and search results using mobx-state-tree?
- How to filter data based on selected value from dropdown menu and search query in input field using reactjs?
- React Hooks and Fetch: How to update a table based on a user input from an API search
- How to structure a component that receives a prop from redux, makes query and saves result back to redux?
- How to filter my search results by location and how to rerender?
- How to handle when no search results are found using material-table with React and remote data
- How to create alphabet and Input Search in React JS
- How to search in a json array, and return the result as I type in the input
- How can i make my checkbox and input search to be inline?
- How I can use an input field as a search field and store data for signup?
- How to send query on submit and display results in prefilled form (React and react hook form)
- How can I use modify and use ‘$and’ in a search query when some items are null?
- How to use React context on search input and share the input with other components?
- Remove query from search input still displays results on page
- I'm trying to display search results for both name and genres for particular TV shows in React, how to use one filter method for both name and genre?
- How do I dynamically switch between screens and update the url during search input
- How to organise file structure of backend and frontend in MERN
- Material-UI: How to show search icon in input field in react?
- How to load more search results when scrolling down the page in React.js?
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- How to render results of search in another component in React?
- How to implement search bar button and result components in react
- How to pass an empty value to DatePicker and avoid input blocking?
- How to put a dynamic data from firestore in the function where() and also use the snap.size to count the total query to be passed in a graph?
- How to filter a list based on user input with ClojureScript and Om?
- How to set defaultValue, value={this.props.value}, and update the value of a text input with React?
- How to structure a React Container and Component to handle a form's lifecycle?
- How to get ReactJS Material-table search results count
- How to test an onChange input event with enzyme and jest
- How can I make my input field prefilled with data and editable on page load?
More Query from same tag
- Keyboard event event.key is unidentified on android webview
- How to use size-limit package?
- HoC with React Hooks
- How to define an interface for React function component with defaultProps without throwing missing type error?
- How do I asynchronously update a variable from a paginated API using React hooks?
- React Hooks won't work on Firebase Cloud Functions Error: Invariant Violation: Invalid hook call
- Navigation with Link and Route is not working
- How to render two different arrays data into a single array of objects?
- I have set the headers then also CORS policy error is there(ReactJS)
- pass data from app.js to components in ReactJs
- anyone know how can i achieve this kind of loading screen for dashboard admin panel website using react?
- Is there a React equivalent of Vue's nextTick() function?
- React app with Server-side rendering crashes with load
- How to make the visited step active?
- I send data as props to components. But, only the last component showing data
- Axios get multiple JSON end points and save into state (react)
- Components with same import in micro-frondends
- React | How to remove prevent.default from state update
- How to add new components with React Router without rerendering prior components?
- How to map a bunch of objects in js to another object
- React render array of objects
- How to store a values of multiple inputs in the state of a mapping React
- Generic React components in TypeScript/JSX?
- react/c# - fetch to c# causes Ssl exception
- ReactDOM.createPortal modal is mounted on DOM but nothing is displayed on the screen
- Can someone help me with this React tutorial syntax error?
- React component library with two different design systems with styled-components
- Change start and end index inside filter
- How to Filter data collection in ReactJS
- How to horizontally scroll in a React Application (ag grid) with UI automation (WebdriverIO /JavaScript)?