|
Ruggan posted:Here's a first pass on how I would do this. Unrelated, but oh my god I hate that comment font/style/color so much
|
# ? May 10, 2019 19:17 |
|
|
# ? Jun 8, 2024 17:11 |
|
OK so I think my issue stems from making an external call? I'm trying (at first) to see if it's a full moon given an API, I'll later check for other celestial happenings in other child components. once I make it a call with AXIOS then what gets returned is changed?? if I use the hardcoded this.isHardcoded() everything seems fine, but if I try to dynamically get the data instead via isMoonFull() then what returns changes? parent: code:
code:
code:
code:
|
# ? May 11, 2019 16:31 |
|
The Merkinman posted:OK so I think my issue stems from making an external call? You are having execution order issues. The quick fix is: make isMoonFull async and instead of using .then, just await the result. You will have to make created() async as well so you can await the result of isMoonFull(). The order of logs on the two different versions is the evidence. With this line: code:
If you really need the logs in that order, then use async/await like I said, otherwise, your actual code isn't wrong, you just have log statements in an odd place which has you chasing a ghost.
|
# ? May 11, 2019 19:17 |
|
Paranda posted:For a phone interview I wouldn't expect them to live code, but yeah I'm looking to hear them describe something like what you implemented, using refs, and then grabbing the height on the element. Surprisingly, a decent # of candidates can't even think of how to do it at all. Not super surprised. You can write a lot of React, including pretty complex apps, without running into refs. Especially if you just use other peoples packages to do the complex bits.
|
# ? May 12, 2019 14:28 |
|
smackfu posted:Not super surprised. You can write a lot of React, including pretty complex apps, without running into refs. Especially if you just use other peoples packages to do the complex bits. Yeah I only used refs I think in one situation for an audio component. Had no idea about that height thing but it is cool after seeing it. But yeah I have never come across that information out in the wild so wouldn't have even considered it. Doesn't feel like as common knowledge as you think it is.
|
# ? May 12, 2019 14:33 |
|
I dunno every React project I've worked on of a decent size seems like it runs into refs sooner or later, usually for grabbing clientHeight/scrollHeight or sometimes for working with canvas. Just depends on what you're building. We like height transitions in our designs and they're useful there. Good point about using packages as there are many "measure dom node size" things out there that people might look at instead of trying to do it with refs. I would say that refs are a fairly important bit of React's API and you should know what they are and that they can be useful for interacting with the DOM. Like "I have read the documentation" level awareness, if you've never had reason to actually use em thats ok.
|
# ? May 13, 2019 15:36 |
|
HaB posted:You are having execution order issues. The quick fix is: make isMoonFull async and instead of using .then, just await the result. You will have to make created() async as well so you can await the result of isMoonFull(). I don't need the logs, they are there for debugging. The issue is since this.isFull in countDumb() is Boolean() { [native code] } instead of an actual Boolean with a true or false value, it's always resolving to true I tried the async stuff you suggested, but it still isn't working, do I need to do some combo of async/await on the parent too?
|
# ? May 13, 2019 18:40 |
|
The Merkinman posted:I don't need the logs, they are there for debugging. The issue is since this.isFull in countDumb() is Boolean() { [native code] } instead of an actual Boolean with a true or false value, it's always resolving to true That's still an execution order problem. You are calling countDumb() in mounted(). There's no way to guarantee when the Parent has mounted that the Child component has finished pulling its data or not. Sometimes it might be, but probably not. And you can't rely on "sometimes" anyway. Instead, you need to call countDumb() when the event is emitted. So inside of checkFull(). The reason to use an emitter is so you know the data call has completed and has data. Calling countDumb() in mounted() is checking for the existence of a thing you aren't sure is there yet.
|
# ? May 13, 2019 19:24 |
|
Typescript question #747123: I am using a library component that allows me to pass a component as a prop. I have a couple props of my own on said component, plus the library component adds some. How do I type this? JavaScript code:
|
# ? May 13, 2019 19:55 |
|
Shouldn't there be a base type somewhere, x and y aren't actually being added magically. If you know what the base type is, then you should be able to just extend it:code:
|
# ? May 13, 2019 20:10 |
|
The Fool posted:Shouldn't there be a base type somewhere, x and y aren't actually being added magically. If you know what the base type is, then you should be able to just extend it: Forgot to say in my original post that I tried that as well and it's the same issue as the posted code. Since I don't explicitly provide values for the `baseCompProps` it yells.
|
# ? May 13, 2019 20:14 |
|
It sounds like that lib should be using an HOC, since that's usually how adding props to a component works, but in this case, I'd probably do something likeJavaScript code:
JavaScript code:
teen phone cutie fucked around with this message at 21:09 on May 13, 2019 |
# ? May 13, 2019 21:06 |
|
Grump posted:It sounds like that lib should be using an HOC, since that's usually how adding props to a component works, but in this case, I'd probably do something like Thanks for this. This library isn't typescript in and of itself, and most of the stuff provided in the DefinitelyTyped types are 'any', so in one sense, it makes it easy since MyType & any pretty much shuts up TS....
|
# ? May 13, 2019 22:18 |
|
Lumpy posted:Thanks for this. This library isn't typescript in and of itself, and most of the stuff provided in the DefinitelyTyped types are 'any', so in one sense, it makes it easy since MyType & any pretty much shuts up TS.... yeah unfortunately that's one of the biggest pitfalls with TypeScript. Most of my Github open-source contributions are just me providing type definitions. But soon or later, you're going to have to end up creating a file called somelib.d.ts and just JavaScript code:
|
# ? May 14, 2019 00:46 |
|
What frameworks/packages/stacks should I look in to if we want to overlay data visualizations on top of a video playback interface? Basically, we have a backend API that provides (the data for) animated 2D charts and a homography matrix for how these charts should be projected onto the ground plane of a video. Imagine a weathermap but on a video rather than a satellite image and you get the idea. (The transformation to 2D coordinates is trivial so we are not limited to 3D options) I'm the backend guy, taught myself enough JavaScript to put the charts next to the video. For this next step I'm passing it off to a hypothetical new hire but I need to be better informed regardless. What technologies should I start reading up on? WebGL? D3?
|
# ? May 17, 2019 17:30 |
|
Have a canvas container that serves as a custom media player that manipulates the state of the video and the charts, blitting the latter into the former. Hardest part about doing that would be seeking. As long as you have a robust enough timeline definition for your charts it shouldn't be that bad, though. WebGL is super overkill here. You could probably do it with some stateful react.js and some css position shenanigans, but I'd just suggest going with the canvas route here.
|
# ? May 17, 2019 19:12 |
|
How I would do it (bear in mind that I've never done such a thing, but I do have a bit of experience with the ffmpeg API) would be to generate the video directly with the things drawn on it and just stream it to the browser. All done on the backend, no need to fluff around with the client. Ability for the client to manipulate the data that is shown (show/hide things) would be possible, but not as straightforward.
|
# ? May 17, 2019 19:46 |
|
Why not just overlay in the browser? https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/timeupdate_event Use that to drive/time the overlay. Re-rendering the video looks like an overkill to me.
|
# ? May 17, 2019 19:59 |
|
gbut posted:Why not just overlay in the browser? Yeah this is how I am synchronizing the chart and the video currently. It works pretty well. Agree that re-rendering is not an option, we have lots of toggles and stuff so there are many permutations and I assume we can't render fast enough to make that smooth. So maybe I've already done the hard part. I was concerned mostly with getting pixel-perfect alignment and making sure it acts like the chart is part of the video even if it isn't. Seems like canvas is the way to go; maybe this is easier than I thought. Thanks all.
|
# ? May 18, 2019 17:41 |
|
The canvas element is super robust and if you're familiar with working with graphics buffers and the math involved in low level rendering, you can optimize it to have comparable performance with WebGL. IIRC support for hardware acceleration has been added to some browsers, too. It's very underrated and fun to work with.
|
# ? May 18, 2019 19:26 |
|
Canvas, definitely, if you're aiming for pixel perfect. It's super easy to work with, or you can use something like p5.js if you want power with even more ease.
|
# ? May 18, 2019 20:48 |
|
You might want to check in with MrMoo. They've been posting about their work rendering stock tickers at a major trade center off and on for years. If there's something they don't know about real time data rendering (though no video involved) I'd be surprised. They have a thread in the project.log about the ticker.
|
# ? May 19, 2019 16:53 |
|
WebGPU is the new upcoming graphics API du jour. Also check some other Google IO 2019 videos for some interesting tidbits, particularly with their game demo, take away is basically get everything off the renderer thread. https://www.youtube.com/watch?v=K2JzIUIHIhc https://www.youtube.com/watch?v=w8P5HLxcIO4 I've recently bumped my ticker work to WebGL2 courtesy of PixiJS v5. It uses more GPU memory and CPU is about all I can say about it. There's a 3 min default GPU old texture purge timer I've noted to disable. Also weird stuff like defaulting to 32 max textures but now in v5 dropping that if the hardware supports less - so you need to set a high default (?) Some pretty demo, but I hate pages that break vertical scrolling, like the Apple Mac Pro page. On my todo list is the following:
|
# ? May 20, 2019 04:45 |
|
GraphQL server question(s): Let's say I have this: JavaScript code:
If I was getting all the data in one big DB call I could do this easily by iterating over the Kids and creating a new one and further iterating over the kidData inside and so on... but I can't do that. I'm guessing there is going to be a schema-transform in there somehow, but I'm sort of stumped on how and where (at what point / in which resolver) to access the kidData and the kids themselves to clone them and add the virtual copies. Anyone done something like this?
|
# ? May 20, 2019 16:46 |
|
Anyone have any experience with doing the following, preferably in HapiJS, since I can't find an example of someone doing it in anything close to the current version, and they had MAJOR changes as of v17 (18 is current), so any example pre v17 is basically useless since the whole api changed: - client hits endpoint - server hits 3rd party servers downloading various things - server creates zipfile of downloaded things and returns it. I am trying to use JSZip for the zipfile, and I can at least get a test one created correctly, but I can't for the life of me figure out how to get Hapi to return it, preferably streaming it as it's being built. I cant even get the correct return with just a test file that's basically: code:
|
# ? May 20, 2019 16:59 |
|
Is anyone here really good with React refs, higher-order components, and 3rd party libs? I for one think refs are extremely confusing and was never good at wrapping my head around them, and I have yet to find a good tutorial that explains how to use refs with HOCs and 3rd party libs. Specifically, my issue here is that I'm trying to focus input on something when a button is clicked. I'm using react-select as the input I want to focus on. react select docs being here: https://react-select.com/home and how to use refs with react select: https://react-select.com/components#inner-ref So I have this parent component, let's call it Form.tsx JavaScript code:
JavaScript code:
https://reactjs.org/docs/hooks-reference.html#useimperativehandle and https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components From what I can tell, my issue is 2 fold: 1. How do I get multiple refs with a render that using .map to render an array of <SearchBar />s? 2. How do I get that parent ref passed down to the input element? teen phone cutie fucked around with this message at 14:41 on May 22, 2019 |
# ? May 22, 2019 05:02 |
|
Grump posted:Is anyone here really good with React refs, higher-order components, and 3rd party libs? I for one think refs are extremely confusing and was never good at wrapping my head around them, and I have yet to find a good tutorial that explains how to use refs with HOCs and 3rd party libs. For question 1, forwarding refs (your second link) is the right idea. Currently you can't use refs the traditional way in your Form component because it's a FC. If you change it a class component you can stick a ref={this.searchInputRefs[index] = React.createRef<HTMLInputElement>()} in your code to create an array of refs, and then let your onClick do things to the desired this.searchInputRefs[index] as needed. Another option that lets you circumvent all this Ref forwarding from Form to Search altogether is to alter your SearchBar component and add something like a "focused" or "active" prop that you can simply subscribe to for the relevant cases. You'd have to add some protection around preventing the SearchBar from stealing focus but this makes whatever internal implementation of autofocus primary to your SearchBar component that deals with inputs, and changes your Form's responsibility simply to deciding which SearchBar is the one should be the one to get the focused prop. Meanwhile you let SearchBar handle what exactly it means to focus on either Input or Select or Dropdown or whatever it is you wanted. I generally prefer to do this with complex Inputs since it helps me reason out the interactions between the components more easily in my head. For question 2, connecting SearchBar ref to Input, since you're passing your own custom Input component into react-select, you'd pass the ref down to the innerRef property based on the documentation you linked (https://react-select.com/props#input) and then hook that up to the ref in your component's HTML input element.
|
# ? May 22, 2019 21:12 |
|
Paranda posted:For question 1, forwarding refs (your second link) is the right idea. Currently you can't use refs the traditional way in your Form component because it's a FC. If you change it a class component you can stick a ref={this.searchInputRefs[index] = React.createRef<HTMLInputElement>()} in your code to create an array of refs, and then let your onClick do things to the desired this.searchInputRefs[index] as needed. Hey that makes a lot of sense thanks. What about useRef. This allows me to now use refs in functional components, right? I imagine if I went the route of using an "focused" prop on my Searchbar, I'd need to set that state when the "add ingredient" button is clicked? And then what exactly would my Searchbar component be doing at that point? Calling ref.current.focus() on the custom input? I'm confused as to where exactly I'd be calling the focus().
|
# ? May 22, 2019 22:05 |
|
Is it still good prac to use triple eq, assuming Typescript?
|
# ? May 22, 2019 22:41 |
|
Dominoes posted:Is it still good prac to use triple eq, assuming Typescript? yeah never use double equal. There's no good reason to not use triple.
|
# ? May 22, 2019 23:13 |
|
It'd be nice to have a Tsconfig var that converts dbl to trpl.
|
# ? May 22, 2019 23:14 |
|
There's a tslint rule you could throw an error on.
|
# ? May 22, 2019 23:18 |
|
After saying I never use refs in React two weeks ago, I’ve used them for two different things this week. For interacting with the video tag, and for setting focus in a form on errors. Very handy when you need it.
|
# ? May 23, 2019 00:34 |
|
Grump posted:Hey that makes a lot of sense thanks. What about useRef. This allows me to now use refs in functional components, right?
|
# ? May 23, 2019 01:14 |
|
Paranda posted:Yeah. It's a bit of a pain in the rear end to wrangle two layers of refs through FCs but I wrote a quick example of how you would do this generally based on your example https://codesandbox.io/s/refs-example-1fc4x Thanks for this. Unfortunately, my button is going under the array of search bar elements so I would probably need to dispatch some custom event and then add an event listener to the last searchbar in the list. I actually tried this tonight, but it ended up not working since the event listener was being dispatched in the onClick of the button. And the problem there is that the DOM was being repainted AFTER the event was dispatched, making it so the second to last searchbar was being focused. I'm really starting to pull my hair out here. I'll try to post an example of my could different approaches tomorrow. I've also found out that using the react-select input doesn't take a ref. Instead it provides a callback function that gives you access to the underlying input element. so like: JavaScript code:
|
# ? May 23, 2019 03:37 |
|
Solved my issue. Here's how: https://codesandbox.io/embed/nameless-leftpad-o3zwl But also I'm running into weird issues now when I start typing the input loses focus and focuses on the body somehow???? wtf? I've got a SO question on what exactly is going wrong for me with this one: https://stackoverflow.com/questions/56285886/react-select-custom-input-losing-focus I'm assuming this is most likely me not understanding something about how React works, rather than this being a react-select bug. https://codesandbox.io/s/reactselect3575-fixed-8u04m e: I now think refs are cool and good. wooohooo! teen phone cutie fucked around with this message at 19:09 on May 24, 2019 |
# ? May 24, 2019 04:54 |
|
Ok sorry I have another question. What's the appropriate way to write debounce logic in React functional components? This works for me, but is there another approach that's more graceful? JavaScript code:
|
# ? May 27, 2019 05:24 |
|
We have a frameset of three frames where the content in the child frames will change when the user clicks an a-tag with a href and a target specifying the frame to load the content in. We want to replace the frames with divs. What's the easiest way to get the same dynamic functionality from the current frameset with divs?
|
# ? May 28, 2019 13:13 |
|
If I had to choose one to learn, should I learn Angular or React?
|
# ? May 28, 2019 13:21 |
|
|
# ? Jun 8, 2024 17:11 |
|
RC Cola posted:If I had to choose one to learn, should I learn Angular or React? Spend some time on job boards, figure out which one is more in-demand in your city, and learn that one.
|
# ? May 28, 2019 13:32 |