Im trying to work with text and im following a tutorial that says in order to work with text just type this
var React = require('react');
var Text = React.Text;
and then you can use it and it works with him
but with me it did not work and gives error says
element type is invalid expected a string
and in order to make it work i wrote
import {Text} from 'react-native';
so why is this difference?
i think that the first one familiar to me than the second one
You are searching in two different places. In the first attempt you are looking inside the react package, which is the same one you would use for React on the web. Of course, it does not make much sense having a React Native-specific component in that package, and that is the reason why you are not finding it. In the second one, you are querying a completely different package, the react-native one, which does have the element you are looking for.
Related
I am kinda new to React Native. I get this warning which is really annoying and spamming the console every other second or so.
EventEmitter.removeListener('appStateDidChange', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
How do I debug this? The call stack says MeasurementProvider, but there is no removeListener anywhere in our code. Does this warning come from a third-party module?
For some reason, I only get this warning in 1 redux slice out of many which use the exact same code structure for deleting state items... Everything works as it should besides that warning popping up so I simply removed the warning using the code below in App.js
import {LogBox} from "react-native";
LogBox.ignoreLogs([
"EventEmitter.removeListener('appStateDidChange', ...)"
])
It's no long-term solution but it'll only show the warning in your dev console this way :)
Here is an image of the top lines of a simple(ish) app.js (not using the bluetooth stuff yet - all commented out)
So no biggie as app seems to work regardless, but I'm interested in why I get it and what can be done to remove it.
Some previous questions seem related to the use of something called Jest (no idea what that is - I suppose I should look it up?)
Jest Testing React Native cannot use import statement outside of a module
Putting it here for benefit of others who may come across it.
I need to make a Vue.js site with a JavaScript Ink interpreter. The only one that seems to be production-ready is Ink.js. There are two ways to import it. One is in its TypeScript format, but my Vue setup does not use TypeScript. I could add it, maybe, although I'm not sure I want to. If I import the TypeScript libraries from Yarn, no matter which object I import, it shows up with a value of undefined in my code.
Then there is a pure es5 script available, that seems to be a transpiled version of the first one, but when I try to import that one, I get this error, I think from Babel:
Uncaught SyntaxError: Unexpected token '!'
cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Ink.vue?vue&type=script&lang=js&:39 Uncaught SyntaxError: Unexpected token '!'
at Object../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Ink.vue?vue&type=script&lang=js& (app.js:962)
My guess is that Babel is set up for es6 or es7 and the pure is5 file brings up some unexpected syntax. I tried to change babel.config.js, but I've found no option that's kept Vue.js from complaining. What am I doing wrong?
After many failed attempts, I went around the problem in the following way: I imported the Story object directly from the library:
import { Story } from '../../node_modules/inkjs/engine/Story';
// ...
let story = new Story(storyText);
I know it's not what the documentation recommends, but it works. And it seems everything else that needs to be imported is, because when I try to read story.currentChoices I get an array of Choice objects that are in turn perfectly readable.
So this works for me. If anyone else runs into this problem, I'm not saying it's the right solution, I'm just saying that's what I finally ended up doing.
https://snack.expo.io/#haosmark/kw-companion
I'm having a hard time figuring this out. To start, I'm just trying to take a list of players and push it over to my starting screen.
A bit of explanation of what I've done so far:
mockData.json is a file with the content that I'm trying to display
App.js creates a few navigators and sets the starting point to be PlayerNavigator
api.js is where I'm thinking of processing json content
redux/reducers/player_reducer.js is how I try to get the player list (reducers are pretty difficult for me to understand right now, so I'm not sure what goes into these files yet.)
screens/list.js is where I'm trying to connect redux to RN and read the player list.
At present, the code doesn't compile. My emulator screams that "players" returned undefined during initialization. Snack editor is screaming "Device: (78:20) Unable to resolve module 'module://mockData.js'" but I have no idea where it's even finding mockData.js since it isn't one of the files within the project.
Edit: I was able to figure out the .json problem for the snack, now the problem is the same as on the local emulator:
Device: (281:119) Reducer "players" returned undefined during
initialization. If the state passed to the reducer is undefined, you
must explicitly return the initial state. The initial state may not be
undefined. If you don't want to set a value for this reducer, you can
use null instead of undefined. Evaluating
module://redux/store/index.js
Just changing import mockData from './mockData' to import mockData from './mockData.json' should do the trick. I can confirm that it works on RN 0.55.2.
Regarding your new error: when you create the store it needs to be initialized with some initial state. It can be passed as the second argument to createStore, but the most straightforward way is to have a default value for the state argument in all of your reducers. For example, if your state.players substate is a list of players, your default argument value can be []. Then, to add or remove players inside your reducers you can use (for example) state.push() and state.pop() and you don't have to care about the prototype of your state object.
AppCode's autocomplete is showing some strange behaviour on my side that I cant seem to figure out. There are two issues I'm currently facing:
Auto complete results are missing or incorrect, in the case below I'm trying to create a CGRect, but only get shown one constructor:
No autocomplete what so ever. In the case below it will not auto complete any functions or properties on UIView.frame. Incidentally, if I create a CGRect and try and autocomplete on that variable, it will show results :
CoreGraphics is the first framework I'm working on where this seems to be a problem. This happens whether I add an import to the top of the file of not.
Any Ideas?