|
I think React escapes strings automatically. Try it without the HTML escape lib.
|
# ? Mar 18, 2017 03:56 |
|
|
# ? May 22, 2024 22:14 |
|
Knifegrab posted:Yeah sorry guys, I was in fact using react and I used the componentWillRecieveProps hook to update the state on re-instancing. I was mistakent. Video Nasty fucked around with this message at 06:42 on Mar 18, 2017 |
# ? Mar 18, 2017 06:39 |
|
Ahh so it would seem react does! I again am a proven bonehead, thanks a ton guys!
|
# ? Mar 18, 2017 08:58 |
|
I think I wrote some JS that is garbage, but I'm not experienced enough to know. I have an array of objects, each object has an id property and a name property. I have another array that is just full of numbers. I'm trying to create a new array out of this one, replacing the id with the name property in the other array. Here's what I have. data.genres.genres array code:
code:
code:
|
# ? Mar 19, 2017 07:20 |
|
Kinda terrible, but not because of the code. It's your data structures. You just need to utilize the indexes on your arrays instead of each entry floating in a relatively anonymous property (really, they have their own arbitrary indices depending on how inserted them). You can just make your array index be the id instead, and each value can be an object or just the string of the genre name, to get a direct reference. More conceptually: Arrays are just normal objects with extra methods tacked on. Array indices are just numeric object properties. You should use them like properties 90% of the time except when you have a particular case to push/pop/splice. Just set it directly, like genres[28] = "action", or in a JSONy way: code:
code:
With this, genre[28] is "action", so your code would be simplified to: code:
Ranzear fucked around with this message at 14:17 on Mar 19, 2017 |
# ? Mar 19, 2017 13:46 |
|
Xom posted:That's just a static page, and I made the images low-res, so yes. Did you try running the demo? I should probably bold that link.
|
# ? Mar 19, 2017 14:07 |
|
Knifegrab posted:
You're double-escaping your text somewhere.
|
# ? Mar 19, 2017 14:29 |
|
Ranzear posted:Kinda terrible, but not because of the code. It's your data structures. You just need to utilize the indexes on your arrays instead of each entry floating in a relatively anonymous property (really, they have their own arbitrary indices depending on how inserted them). Ah, nice that seems way easier. I agree on the data structure being dumb. The genre array and movie arrays are coming from an outside API. I wanted to try doing a little back end stuff and already had an express server set up for server-side rendering .ejs templates, so I thought I'd write a small API that the client talks to to get movie data, and have the server construct the data in something easier for the client to consume. I'm definitely going to have the server convert that genre array into an object before it gets passed into the function that constructs the data to pass back to the client so I'm not looping over it unnecessarily for each movie. Edit: Jesus, that made the code that builds the movie list for the client so much cleaner. code:
ddiddles fucked around with this message at 22:16 on Mar 19, 2017 |
# ? Mar 19, 2017 21:35 |
|
ddiddles posted:Jesus, that made the code that builds the movie list for the client so much cleaner. You can also trim this down a little more: code:
code:
|
# ? Mar 19, 2017 22:33 |
|
Oh, I thought .map() required a return statement in the callback? Edit: On further reading, I was mixing that up with wanting to return something from the forEach callback. Nice, refactor upon refactor upon refactor. ddiddles fucked around with this message at 23:00 on Mar 19, 2017 |
# ? Mar 19, 2017 22:57 |
|
ddiddles posted:Oh, I thought .map() required a return statement in the callback? If you have an arrow function without a block, the single statement in it is automatically returned. The ({}) syntax serves as a disambiguation for object literal vs function block.
|
# ? Mar 19, 2017 23:11 |
|
And just to clairfy what Roadie said because I myself am an example man:code:
code:
|
# ? Mar 20, 2017 05:17 |
|
Knifegrab posted:And just to clairfy what Roadie said because I myself am an example man: If it's only a single parameter, you don't even need the parentheses around it. code:
code:
Roadie fucked around with this message at 05:59 on Mar 20, 2017 |
# ? Mar 20, 2017 05:49 |
|
Roadie posted:If it's only a single parameter, you don't even need the parentheses around it. True but as a rule of purpose I always use wrap my arrow function parameters. I think its a good practice to follow IMO. Obviously this is highly debatable.
|
# ? Mar 20, 2017 18:38 |
|
Knifegrab posted:True but as a rule of purpose I always use wrap my arrow function parameters. I think its a good practice to follow IMO. Obviously this is highly debatable. The unwrapped version is interesting because it implicitly returns the expression, so not only do you save on () {}, but the return statement as well. Works best for trivial things, if complex would probably be best to break it down further, though in that case would probably make more sense to move it to a dedicated function instead of anonymous.
|
# ? Mar 20, 2017 20:51 |
|
I love es6. Thanks for the explanation dudes!
|
# ? Mar 20, 2017 21:06 |
|
Skandranon posted:The unwrapped version is interesting because it implicitly returns the expression, so not only do you save on () {}, but the return statement as well. Works best for trivial things, if complex would probably be best to break it down further, though in that case would probably make more sense to move it to a dedicated function instead of anonymous. Only unwrapping the {} implies the return. Whether or not the paramters are wrapped don't affect the implied return. Unwrapping the parameters only works when there is a single parameter as well, so its such an edge case I always wrap my parameters. I think it reads better.
|
# ? Mar 20, 2017 21:18 |
|
Hey dudes. How can I make React work? The tutorials I'm seeing focus on JSX syntax, then link to node packages. This is a front-end-framework that shouldn't have anything to do with node AFAIK, so I'm missing something. How do I run a JSX file on a web page, without worrying about server-frameworks and package managers?
|
# ? Mar 20, 2017 22:56 |
|
Dominoes posted:Hey dudes. How can I make React work? The tutorials I'm seeing focus on JSX syntax, then link to node packages. This is a front-end-framework that shouldn't have anything to do with node AFAIK, so I'm missing something. How do I run a JSX file on a web page, without worrying about server-frameworks and package managers? People working with React commonly use npm for package management and node+express as a local dev server. They are by no means required and you can run react using <script> tags if you really wanted to. I'd recommend just using create-react-app and not worrying too much about what's going on behind the scenes if you're just starting out. Create-react-app: https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html
|
# ? Mar 20, 2017 23:05 |
|
Dominoes posted:Hey dudes. How can I make React work? The tutorials I'm seeing focus on JSX syntax, then link to node packages. This is a front-end-framework that shouldn't have anything to do with node AFAIK, so I'm missing something. How do I run a JSX file on a web page, without worrying about server-frameworks and package managers? At a high level: People using React use a thing called webpack. Webpack takes node modules and bundles them up into a javascript file that you then include in your page via a script tag. This is nice because you can install all sorts of libraries and use them in your frontend work kind of like you didn't have to work in the terrible environment that is the browser. So, I know you do python so it kind of works like this: npm install react is the equivalent of pip install requests. package.json is kind of the equivalent of requirements.txt When you're developing you can use a thing called webpack-dev-server that automatically rebundles your code and all of the dependencies when you save a file and then refreshes your browser pages showing your app. When you're ready to put your code into production you call the appropriate commands to tell webpack to spit out a bundle.js file that contains all your code as well as all the libraries you've installed with npm install. create-react-app streamlines a lot of the process here...particularly for beginners, so I'd recommend you use that and ask questions as you work with it.
|
# ? Mar 20, 2017 23:16 |
|
Thanks dudes. Ironically, it was installing create-react-app, and seeing webpack in search results that made me even more confused. Looks like this is no ordinary JS library!
|
# ? Mar 20, 2017 23:28 |
|
It's possible to use react without using NPM or webpack for bundling, but just thinking about it makes me anxious. People use Webpack and Babel because it allows you to write this: code:
code:
Edit: Guess its not bad. code:
ddiddles fucked around with this message at 23:43 on Mar 20, 2017 |
# ? Mar 20, 2017 23:39 |
|
Can someone give me the cliff notes on what the curly braces do in this ES6 import statement? code:
I'm new with ES6 / transpilers / webpack / etc. Coming slowly, but there are so many magic wands. Here's the error message that I got: quote:Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `ParentComponent`
|
# ? Mar 21, 2017 22:19 |
|
Curly braces mean you're importing a non-default member. export default butts import butts export butts export dongs import {butts, dongs}
|
# ? Mar 21, 2017 22:21 |
|
Kekekela posted:Curly braces mean you're importing a non-default member. Member of... the file? This is a toy / tutorial project, and sourceFile.js consists only of some import lines and a single code:
edit: Your edit provides a bit more context to chew on. Will play with some keywords. Wish me butts.
|
# ? Mar 21, 2017 22:27 |
|
exporting essentially generates the following objectcode:
code:
|
# ? Mar 21, 2017 22:38 |
|
ddiddles posted:It's possible to use react without using NPM or webpack for bundling, but just thinking about it makes me anxious. What's the best way to make TypeScript not throw the error 'property value does not exist on type Element' for code like this?: JavaScript code:
Dominoes fucked around with this message at 20:26 on Mar 23, 2017 |
# ? Mar 23, 2017 20:24 |
|
I've been fed up with Polymer's dropdown functionality, so I decided to edit a w3schools example. Seems to work fine on PC browsers, but I can't seem to implement a way to have it work on iOS to capture touches outside the button and menu to close it. If I use a touchend event listener the same way I use click, it closes the menu immediately after I try touching an option on the list. CSS: code:
code:
code:
|
# ? Mar 24, 2017 21:06 |
|
Another ES6 / React question. I'm following this Lynda.com React.js Essential Training course, which I'm generally finding informative and good, but I'm often thrown for a loop at some of the author's js conventions. I'm new to ES6 and bad at js in general, but I'm really stuck for rationale at some of the code she writes. The current example is a function for adding an item to a component's array of data: JavaScript code:
|
# ? Mar 24, 2017 22:54 |
|
Newf posted:It feels like a lot of modern language features are being shoehorned in for their own sake, but I don't feel very qualified to be making these judgements. State changes should only ever be made through the setState method so that React can trigger updates and lifecycle methods. If the '...' business is confusing, it's called the Spread Operator, you can think of it as unzipping the members of this.state.allSkiDays and placing them in to the new allSkiDays array, along with another item, newDay https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator If it helps, that could also be written without it like this: code:
ROFLburger fucked around with this message at 23:08 on Mar 24, 2017 |
# ? Mar 24, 2017 23:05 |
|
Newf posted:Another ES6 / React question. E: I'm an idiot, so rarely do I use the return of push that I forgot it was the length not the array. It does, however a thing to keep in mind is push on its own will mutate the old state and return not the array but the length, an identical result would come from allDays.concat([newDay]) Maluco Marinero fucked around with this message at 23:22 on Mar 24, 2017 |
# ? Mar 24, 2017 23:08 |
|
Newf posted:Another ES6 / React question. spread gives you immutability which can be an important consideration. Its what you'll find being used in reducers in redux for example (this is actually where I started using them because it was necessary which lead to me using them all over the place because it was convenient)
|
# ? Mar 25, 2017 10:38 |
|
ROFLburger posted:State changes should only ever be made through the setState method so that React can trigger updates and lifecycle methods. This is the key thing. Other current frameworks do the details differently, but there's always some level of mushy workaround to be able to reliably detect that you changed X and have that trigger all your things that are watching for new values of X. This isn't necessary for all uses, but it's generally just a lot easier to structure everything that way and then you can throw in "send a thing to the server when this value changes" or "handle JS-based resizes of components incorporating window size" without having to rebuild everything to accommodate it. Roadie fucked around with this message at 21:48 on Mar 27, 2017 |
# ? Mar 27, 2017 21:44 |
|
ES6 is awesome, but I'm also weary of using it since the compatibility is so recent for iOS. I can use babeljs.io to convert it over into something equivalent, but I wish I could just keep writing ES6 and have it convert over behind the scenes. I'm using VS Code. Any good solutions for this?
|
# ? Mar 27, 2017 22:04 |
|
LP0 ON FIRE posted:ES6 is awesome, but I'm also weary of using it since the compatibility is so recent for iOS. I can use babeljs.io to convert it over into something equivalent, but I wish I could just keep writing ES6 and have it convert over behind the scenes. I'm using VS Code. Any good solutions for this? The toytorial work that I've been doing has a fancy setup with npm and Webpack, in conjunction with babel which watches the directory and recompiles whenever there are file changes, and serving the compiled project. JavaScript code:
|
# ? Mar 27, 2017 22:17 |
|
Newf posted:That said, I'm still lost as to how to debug this ES6 code, since all of it ends up bundled If you're in chrome dev tools in the sources tab go down to the bottom of the treeview and select your source files from the webpack node. Might need to enable sourcemaps in your webpack config for that to work. And webpack-dev-server is doing the hot reloading, not babel.
|
# ? Mar 27, 2017 22:29 |
|
LP0 ON FIRE posted:ES6 is awesome, but I'm also weary of using it since the compatibility is so recent for iOS. I can use babeljs.io to convert it over into something equivalent, but I wish I could just keep writing ES6 and have it convert over behind the scenes. I'm using VS Code. Any good solutions for this? Related: Why does TypeScript support only a subset of ES6 compiling to old JS? Are there any compilers that do Typescript and full-ES6? Dominoes fucked around with this message at 02:57 on Mar 28, 2017 |
# ? Mar 28, 2017 00:40 |
|
Dominoes posted:I'm a JS noob, by PyCharm does it automatically for TypeScript; needed to make a tsconfig.json, and enable compiler in the settings. And like Kek said, Chrome's web tools will link the errors to your pre-compile file. Firefox doesn't, at least by default. Typescript is less aggressive in supporting features that are not actually 100% confirmed to be implemented yet. Babel contains all sorts of transpiles that may not actually ever make it into native support. Babel can sort of get away with that because of its configurable nature and no actual promise of backwards compatibility, however that does mean 20 projects using Babel may in fact be using 20 slightly different variants of the JavaScript of the future, depending on how they've been configured.
|
# ? Mar 28, 2017 01:19 |
|
Newf posted:The toytorial work that I've been doing has a fancy setup with npm and Webpack, in conjunction with babel which watches the directory and recompiles whenever there are file changes, and serving the compiled project. Add "devtool: inline-source-map" to your webpack config
|
# ? Mar 28, 2017 01:28 |
|
|
# ? May 22, 2024 22:14 |
|
LP0 ON FIRE posted:ES6 is awesome, but I'm also weary of using it since the compatibility is so recent for iOS. I can use babeljs.io to convert it over into something equivalent, but I wish I could just keep writing ES6 and have it convert over behind the scenes. I'm using VS Code. Any good solutions for this? Have you checked out jspm?
|
# ? Mar 28, 2017 16:01 |