|
So I have been working with react for a while, but I have a question about something I guess I have yet to really deal with. I have a huge associative array that I pull from a server. This array actually informs a ton of information for a ton of componenets. Obviously I don't want to have to pull this array from the server for each component that is rendered (that is a huge waste of data calls obviously). I guess I could pass it to every single component as a prop but that just seems like a huge hassle. Is there any other way to do this? About 1/4 of all components will need access to this information... I'd like my main app.js to just pull it once and then somehow have it readily accesible to any component that needs it?
|
# ? Dec 26, 2016 11:51 |
|
|
# ? Jun 3, 2024 23:58 |
|
If you want something available to the whole tree you can use contexts: https://facebook.github.io/react/docs/context.html This article is kind of hilarious though because context is precisely what Redux uses to do it's thing. I feel it's perfectly fine to use context if you guard it with some sort of API method, so if things change down the track you can make it fit, I use this sort of thing as my base component to do that: code:
e: Just to emphasize, your situation seems like maybe Context is a bad idea, just suck it up and pass the props like you're meant to, but of course Context is the tool if you want something accessible to anything in the tree.
|
# ? Dec 26, 2016 12:36 |
|
Posting to personally recommend the Learning ReactJS video series on Packt. It's on sale for $5usd (also everything there is $5 right now). The author of the corresponding book made it personally and put a lot of effort into explaining everything that's going on. Also posting to personally... whatever the opposite of recommend is... the "Nodejs Projects" video series. It's like the polar opposite of the reactjs one.
|
# ? Dec 26, 2016 14:51 |
|
Maluco Marinero posted:If you want something available to the whole tree you can use contexts: https://facebook.github.io/react/docs/context.html My data will maybe change two to three times a year so context sounds great! Also what is the best way to fetch data since using ajax off jquery seems kind of not worth it when using purely react these days? Knifegrab fucked around with this message at 19:07 on Dec 26, 2016 |
# ? Dec 26, 2016 18:34 |
|
axios is pretty good
|
# ? Dec 26, 2016 19:17 |
|
I always use fetch unless there's some specific need for one of the few extra features axios gives you. Mainly because of yet-another-library fatigue. It's got pretty good browser support, and github makes a good polyfill for those browsers missing it.
|
# ? Dec 26, 2016 21:22 |
|
Thanks guys, axios is pretty much an ajax look alike with promise support so I went that direction. Now I am tearing my hair out over something incredibly simple... Alright I got a css (or sass which I am using) question. Say I have an object that utilizes a sprite sheet. My sprite sheet has over 500 elements stacked vertically (all the same width), I have added a class to the image for the sprite called "offset-x" where x is the element in the sprite sheet. Without having to write a billion classes that each handle what the offset is in sass, is there a way to have it compute the offset within the sass or style sheets? Or would I have to do this as an inline comment in my render function? Knifegrab fucked around with this message at 22:05 on Dec 26, 2016 |
# ? Dec 26, 2016 21:44 |
|
Directives, yo.code:
code:
Anony Mouse fucked around with this message at 01:11 on Dec 27, 2016 |
# ? Dec 27, 2016 01:06 |
|
Thanks. Turns out using sprite sheets for anything that needs to be resized is a huge pita so I'm scrapping that, it would only be a nominal performance boost anyway edit: Ugh I am running into so many tiny little problems writing a broader scale react app. OK so I have a handler I have bubbled down to a child component. This child component when acted upon will then set the state of the parent components. So I have passed a reference to the child component as a prop. Then in the child component I do this: code:
code:
double edit: Apparently the answer seems to be doing this.setParentState = this.setParentState.bind(this) in my constructor. Is there no better way to do this? (No I cannot use the es7 trickery) Knifegrab fucked around with this message at 10:20 on Dec 27, 2016 |
# ? Dec 27, 2016 01:22 |
|
The Wizard of Poz posted:They're not saying that they will rank your page higher or lower, they're not talking about pagerank at all. They're saying that the content included in the result text will be drawn from your page using a mobile-first approach. If your content is the same when visited on mobile and on desktop, (including not having a mobile version at all) then you won't see any difference. quote:our algorithms will eventually primarily use the mobile version of a site’s content to rank pages from that site, to understand structured data, and to show snippets from those pages in our results.
|
# ? Dec 27, 2016 12:40 |
|
Its me back with another inane webdev question. I am using the transition property on a couple of things. In one case I am using transform: scale(2) when you hover over one of hte many flaoted items inside a container to indicate selection, it works really well but unfortunately there is a weird effeect I don't love, its not the end of the world but I would want to be able to still select the adjacent children elements where their normal boundary is but the scaled float covers it. Not a huge thing because the scaled item only covers a small portion of the adjacent elements but just something that is bugging me. Also the right most element in the float container causes the whole layout to break when transformed. Also I was wondering if there was a way to keep an image unskewed inside a container that is transform:skewed but have it fill the container up to the edges. I have tried a couple things but cannot get it to work. Sorry for all the questions as of late, normally my scope for projects is small but I am doing a full blown top to bottom this week.
|
# ? Dec 27, 2016 18:45 |
Knifegrab posted:Its me back with another inane webdev question. pointer-events: none can help you with the first one. The second can be done by scaling the image up I guess. https://jsfiddle.net/py7gojst/
|
|
# ? Dec 27, 2016 19:24 |
|
gmq posted:pointer-events: none can help you with the first one. The second can be done by scaling the image up I guess. Hmm for some reason my hovered images now just flicker a ton... not sure why need to figure this out. Thank you though you have solved the rest of my issues. Knifegrab fucked around with this message at 19:56 on Dec 27, 2016 |
# ? Dec 27, 2016 19:51 |
|
Pay close attention to how his jsfiddle is structured. Each image is wrapped in a li element which is what captures the hover event. You don't want the img to directly capture the hover because then if you add pointer-events: none to it you get stuck in an infinite loop of hovering and then ignoring hover.
|
# ? Dec 28, 2016 01:16 |
|
Anony Mouse posted:Pay close attention to how his jsfiddle is structured. Each image is wrapped in a li element which is what captures the hover event. You don't want the img to directly capture the hover because then if you add pointer-events: none to it you get stuck in an infinite loop of hovering and then ignoring hover. Yup I got it. Man CSS is so fiinicky. Right now I am wrestling with a skewed button whose text I don't want skewed which I got working but now for whatever reason the text is terribly aligned. I found this jsfiddle: https://jsfiddle.net/g812h9L3/40/ And my setup is, as far as I can tell, exactly the same yet my text falls out of the button as I size it down. edit: Solved that onto the next big gently caress up I'm sure! double edit: Alright new question. Handling a KeyDown event, what's the quickest and easiest way to ignore all e.key types that aren't just alphanumerics (there are a TON of special key types I don't care about!) Knifegrab fucked around with this message at 12:56 on Dec 28, 2016 |
# ? Dec 28, 2016 08:43 |
|
Knifegrab posted:double edit: Alright new question. Handling a KeyDown event, what's the quickest and easiest way to ignore all e.key types that aren't just alphanumerics (there are a TON of special key types I don't care about!) Style Guide Question So we're slowly rolling out a brand style guide. However, we're still not done rolling it out to all of our pages and now Creative is getting bored so on new projects they are just reinventing the style guide. This isn't good because these reiventions are also not updating previous pages so we're headed back to bespoke pages where they individually look nice but site-wide they don't (and it's not as scalable/maintainable) again. Is this normal? If not, how do I stop it?
|
# ? Dec 28, 2016 16:18 |
|
The Merkinman posted:check if the keycode is not between 48 and 90 inclusive?
|
# ? Dec 28, 2016 16:52 |
|
Anony Mouse posted:The whole point of having style guides is twofold... enforce consistent brand and visual identity across as many products as possible, and save designers time by having an existing system to pull from. They're not only making more work for themselves but they're actively sabotaging the consistency of your visual brand. Tell them to hold their horses and wait for the final version of the style guide or at least incorporate as much of the established progress as they can. Sorry for your dumb Creative. They don't care about the extra work for me/code bloat/etc because it's not their problem.
|
# ? Dec 28, 2016 17:46 |
|
The Merkinman posted:check if the keycode is not between 48 and 90 inclusive? According to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode this is being deprecated. Also I am assuming CSS cannot detect a content change correct? I am trying to write somehting so that when it detects user input changing it displays the text in an overlay briefly, then it fades out. Currently I am going to use a setTimeout deal to change the class on the overlay with a transition css style on the changes, I suspect this the best approach? edit: Arg my z-index property decided to randomly fail and now my popups are rendering behind other content! Oh wtf using the "filter" css property fucks up z-index?! Wtf how would I have known that, I have no clue how to fix it too... Knifegrab fucked around with this message at 21:08 on Dec 28, 2016 |
# ? Dec 28, 2016 19:52 |
|
Knifegrab posted:According to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode this is being deprecated. Knifegrab posted:Also I am assuming CSS cannot detect a content change correct? I am trying to write somehting so that when it detects user input changing it displays the text in an overlay briefly, then it fades out. Currently I am going to use a setTimeout deal to change the class on the overlay with a transition css style on the changes, I suspect this the best approach? When exactly do you want it to change? Would it be better to use onchange or onblur instead?
|
# ? Dec 28, 2016 21:11 |
|
The Merkinman posted:
Have lunch with them and talk to them about it. Ask for them to send you styleguide resources they have... then when they don't send you any, or send you few, send them a bunch that you "happened to come across". Talking to people solves a great number of problems.
|
# ? Dec 28, 2016 21:49 |
|
Lumpy posted:Have lunch with them and talk to them about it. Ask for them to send you styleguide resources they have... then when they don't send you any, or send you few, send them a bunch that you "happened to come across". Talking to people solves a great number of problems. Right now everyone is gone for the holiday season. I do think some sort of meeting needs to happen, sure. I didn't know the best way to go about it that wouldn't end up as some sort of Dev VS Creative fight.
|
# ? Dec 28, 2016 22:24 |
|
The Merkinman posted:OK, regex? ^[a-zA-Z0-9]*$ Yeah that regex solution could work! Thanks I was thinking about regex but my regex-fu is stupid lovely. I ended actually just checking if hte .key length was of 1, because in my testing I found that all the special functions were strings with length > 1. Its a hacky fix and doing a regex check is probably better. I actually got it working, whenever a valid key is pressed I change the div class and then after a short timeout I change it back. Then I just use the transition property in the CSS one way, it works pretty cleanly! Got another question, what is the best way to load an image in react but not display it till its fully loaded. Right now I am hiding it using display none, and then when the onLoad event handler fires off I change the class to let it be displayed. Seems to work but wondering if there are better methods.
|
# ? Dec 28, 2016 22:57 |
|
So for a React website, does almost everything the user sees and interacts with end up being an extension of ReactComponent? Because this book/video seems to imply that.
|
# ? Dec 29, 2016 04:29 |
|
Love Stole the Day posted:So for a React website, does almost everything the user sees and interacts with end up being an extension of ReactComponent? Because this book/video seems to imply that. Every element React puts on screen is a component. So "yes", but components can be complex ES6 classes, created with React's createClass method, or be really, really simple pure functional components like this: JavaScript code:
Lumpy fucked around with this message at 17:47 on Dec 29, 2016 |
# ? Dec 29, 2016 17:42 |
|
Huh so I have a div that contains and image and some text. I then perform a transform: scale() on the div and in chrome is works hunky dory. But in firefox the text becomes incredibly blurry as does the image (the image is such a size that when scaled up it becomes its native res so I am not overly stretching the image). Has anyone run into this problem?
|
# ? Dec 29, 2016 18:37 |
|
It's pretty common because the way transform works is the image is sort of still scaling based on its pre transform size. Mileage may be different on retina displays, but yeah for Firefox, even chrome, you can end up in scaling problems that seem to blur way more than they should. Two options: - have the image full size and transform 'down' to the resting size. - have two images, one at full size, one at resting size. The transition then becomes opacity & scaling when bringing in the full size image. Maluco Marinero fucked around with this message at 21:41 on Dec 29, 2016 |
# ? Dec 29, 2016 21:15 |
|
Maluco Marinero posted:It's pretty common because the way transform works is the image is sort of still scaling based on its pre transform size. Mileage may be different on retina displays, but yeah for Firefox, even chrome, you can end up in Salina problems that seem to blur way more than they should.
|
# ? Dec 29, 2016 21:31 |
|
Anony Mouse posted:Option three: resize the image and text using width/font-size respectively and avoid transform altogether. Option three is only an option if you're not intending to animate, which I didn't necessarily consider, but then if you're using transform and not animating you need to be sure there's no other way you can do it as it's rarely the ideal for best presentation.
|
# ? Dec 29, 2016 21:41 |
|
I think option three is harder for this. It's a closely grouped amount of images that expand to cover the neighbors. I might try the second element at full size absolutely positioned over the thumbnail version just hidden... It's a PITA when it works flawlessly in chrome. Stupid Firefox!
|
# ? Dec 29, 2016 23:39 |
|
HappyHippo posted:I've been wondering this myself. I've been working on a site with a lot of diagrams to go with the text, and I want it so that on wide enough screens some diagrams move to a second column alongside the text, while on narrower screens everything is just a single column. I've got this working fine using "display: inline-block," but every now and then I come across a situation where the best two column layout would require the content in a different order than the best single column layout, and I can't decide which to favour. I feel like the best solution might just be to duplicate some stuff with one element hidden and use a media query to switch between them. Just touching back on this, I still haven't really figured out if there is a good way to do this other than just hidden content that is made visible when the screen sizes down. Kind of a real pain.
|
# ? Dec 31, 2016 05:16 |
|
Knifegrab posted:Just touching back on this, I still haven't really figured out if there is a good way to do this other than just hidden content that is made visible when the screen sizes down. Kind of a real pain. Flexbox with min-widths, flex wrap on, and re-order elements (via flexbox) in a media query when appropriate.
|
# ? Dec 31, 2016 07:19 |
|
Speaking of flexbox, is there an industry standard of what versions of older browsers you should support? I see that flexbox is supported in Edge, but is apparently buggy in IE11, and unusable in anything before that? Is it recommended to write standard float fallbacks?
|
# ? Dec 31, 2016 11:32 |
|
ddiddles posted:Speaking of flexbox, is there an industry standard of what versions of older browsers you should support? Browser support really depends on the audience of the particular site you're developing.
|
# ? Dec 31, 2016 16:04 |
|
So I pass a props array to a component. Sometimes I reorder that array but my component doesn't update, and I'm guessing its because it is only looking at the top level of the arraay and since its just a sort the actual reference doesn't change. Copying the whole array seems like a process intensive thing, is there another way to force the copmonent to update. I wuld assume I could try and use ComponentWillReceiveProps but I am not sure if that will even be invoked since I doubt it sees this as a prop change... The weird thing is I am slice the array so I would imagine the array reference is chanigng which I htought would cause a re-render in react. This is quite annoying. Knifegrab fucked around with this message at 20:36 on Jan 1, 2017 |
# ? Jan 1, 2017 19:17 |
|
Knifegrab posted:So I pass a props array to a component. Sometimes I reorder that array but my component doesn't update, and I'm guessing its because it is only looking at the top level of the arraay and since its just a sort the actual reference doesn't change. Copying the whole array seems like a process intensive thing, is there another way to force the copmonent to update. I wuld assume I could try and use ComponentWillReceiveProps but I am not sure if that will even be invoked since I doubt it sees this as a prop change... Without seeing code it is hard to help as it could be one of a billion things depending on where and how you are sorting the array. I'm assuming React, but you don't say that explicitly.
|
# ? Jan 1, 2017 22:40 |
|
Just finished the Learning ReactJS book on Packt (it's on sale for $5 atm fyi). Learned the basics about React, Babel, Webpack, JSX, and Redux. Already learned about Node a while ago. Can anyone here give me a direction to go? Something to look up? A Book or video course to buy (preferably on Packt because everything there is $5 right now)? Or should I buy a "building react applications" book and work through those?
|
# ? Jan 2, 2017 02:27 |
|
Is there something specific that you are still trying to learn? If you've already gotten the basics then get out there and start making stuff. Experience is the best teacher.
|
# ? Jan 2, 2017 03:09 |
|
Knifegrab posted:So I pass a props array to a component. Sometimes I reorder that array but my component doesn't update, and I'm guessing its because it is only looking at the top level of the arraay and since its just a sort the actual reference doesn't change. Copying the whole array seems like a process intensive thing, is there another way to force the copmonent to update. I wuld assume I could try and use ComponentWillReceiveProps but I am not sure if that will even be invoked since I doubt it sees this as a prop change... This is what keys are for. Give each element in your array of components a key that is relevant to its contents (not the index) and that should solve the issue.
|
# ? Jan 2, 2017 03:12 |
|
|
# ? Jun 3, 2024 23:58 |
|
Anony Mouse posted:Is there something specific that you are still trying to learn? If you've already gotten the basics then get out there and start making stuff. Experience is the best teacher. I've learned the hard way that when for programming stuff, you cannot just go from 101 and 202 level stuff to just going out there and making things. There's an education gap. That's why I'm posting here about it. As for something specific I want to do, I had the idea of creating a Korean-vocabulary-learning site (because I live there) a la Wanikani. I have a basic uml thing that I sketched out recently:
|
# ? Jan 2, 2017 05:45 |