问题标签 [mobx-react]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
reactjs - 如何在 sessionStorage 中保存 Mobx 状态
试图从本质上完成这个https://github.com/elgerlambert/redux-localstorage这是为 Redux 但为 Mobx 做的。而且最好是想用sessionStorage。有没有一种简单的方法可以用最少的样板来实现这一点?
arrays - MobX 将简单数组从可观察对象传递给观察者
我是 MobX 的新手,在这里被推荐。我有一个简单的数组,我试图将它传递给另一个文件。我已经尝试了很多东西,但我无法以 this.props.store 的形式接收数组如果您能对我对 mobX 的不当使用有所了解,将不胜感激。谢谢你。
然后第二个文件需要观察数组
arrays - Export and import observable MobX React Native
I am new to React Native and very new to MobX, only realising i needed it when my first project demanded dynamically updating and changing props/store between files.
Here is the github of the project: https://github.com/Kovah101/GenreGeneratorv1
I am trying to build an app that generates the name of random genre of music. My main file renders all the components and has a small console.log to check that random numbers are being generated. I don't get any errors here
Next, GenerateButton renders a button with an onClick
event that generates an array of random numbers, these get checked by mainOriginal
and work correctly. I also use MobX to make randomNumbers
observable as it is constantly updated and will be passed to the final file genreSelector
.
genreSelector should use the array of random numbers map them to the size of the 3 different genre arrays, then render 3 boxes, each with one of the random genres from each array. However I get unexpected tokens at 'chosenRandoms' if i set it to be a 'var' and the same again at 'get randomGenres`, my understanding is they need to be something.
Does anybody have any ideas on what i'm doing wrong? If i take the var
and get
out then i get an error at the end of the math manipulation line. I must be misusing something. Thanks for any help, I can provide more of my code but i dont think the problem is in the stylesheet or index.
reactjs - 没有装饰器的reactjs mobx不起作用
我正在尝试mobx
与react
. 由于我使用 生成了我的应用程序create-react-app
,因此我不能使用 mobx 提供的装饰器。
鉴于我们可以按照本文档使用不带装饰器的 mobx:https ://mobxjs.github.io/mobx/best/decorators.html
这是我创建的一个组件:
这是对上述组件的简单调用:
现在,当我运行上述组件时,出现错误:Uncaught TypeError: (0 , _mobxReact2.default) is not a function(…)
控制台中没有显示任何内容。
我在这里做错了什么?
arrays - webpack + mobx + React :需要一个可观察的图像数组
我正在使用 mobX 为这样的画廊存储图像数组:
我有我的缩略图数组、完整图像数组和移动图像数组。
然后我映射数组并将它们用作背景图像或在我的组件中的图像标签中使用(url通过道具传递):
但是当我为 prod 构建时,因为不需要图像并且 url 保持像 src/assets/photos/people/' 他们显然不会显示
所以我试着简单地要求他们:
但我得到一个错误:
我尝试将商店中的路径更改为相对路径:
同样的错误:
我的输出和文件加载器的 webpack 配置:
当我通过 Import 导入单个图像时,一切正常,但是当涉及到这个 observable 时我被卡住了。我也尝试了 require 上下文,但老实说,我并没有真正理解我在做什么,我认为一旦映射我应该能够简单地要求我的图像。
谢谢。
reactjs - React + Mobx:尝试更新商店时“this”为空
刚开始使用 Mobx 和 React 并且无法更新商店。单击按钮时出现错误,该按钮应更新“me”属性:
我的店铺:
组件:
我可能错过了它如何工作的一些基本部分,但无法弄清楚。
reactjs - React Mobx - 商店更改后组件不更新
使用 Mobx,在更新商店(即单击按钮)后,组件不会重新渲染。我已经安装了 mobx devtools,它在初始加载后什么都没有显示,并且控制台中没有错误。任何想法我做错了什么?
商店.js:
布局.js:
index.js:
reactjs - 如何使用 webpack 从包中排除 mobx 和 mobx-react
我想将它们从捆绑包中排除,以便它们可以被浏览器缓存。我在 webpack.config.js 中尝试了这个和一些变体但没有成功。react 和 react-dom 工作正常。
我把它们放在我的 index.html 中
我收到此错误:
谢谢你的帮助。
javascript - mobx:array.map() 不是函数
我创建了一个商店,使用mobx
如下:
然后我在我的 React 视图中观察该商店:
在第一次渲染时,我的视图工作得很好(尽管数组Feed
中没有项目)。InfluencerFeedStore.data
如果我稍后通过调用加载项目InfluencerFeedStore.setData()
,React 将正确尝试重新渲染Feed
视图(因为它注意到 mobx 可观察对象已更新)......但我收到一个错误,抱怨InfluencerFeedStore.data.map is not a function
.
通过阅读mobx
文档,我发现重新分配我的data
属性是有问题的,因为它是一个数组(而其他数据类型,如字符串“正常工作”)。谁能告诉我我在这里做错了什么?
reactjs - React - 处理父组件中的事件
我正在使用几个通用组件来提高可重用性,例如列表、按钮、表格等。这些组件都有一个控制器类,用于处理同一组组件之间的所有属性,例如 listItem、listContainer、listHead。我的问题是如何使用列表将事件从控制器冒泡到父组件。
父组件调用列表
列表组件(创建 ListController 的新实例)
列出控制器类
请问如何从父组件访问点击事件?