News for hackers. Stuff that matters.
Re:React 16 by orb_yt on Tuesday September 26, 2017 @12:33PM (#15340215)
Lovely. The file size reductions are quite surprising.

Removing the need to wrap sibling elements in a single parent element is a welcome change.

I'd be interested in hearing some use cases for using the Portal API.

Lastly, the new licensing announced last week was fantastic news. I commented on last weeks thread, but I want to extend another round of compliments to Facebook and the React community as a whole for prompting this change. Props to them.

Re:React 16 by humblebee on Tuesday September 26, 2017 @01:54PM (#15341015)
We use portals quite a bit in our application and they always are a pain to test. This is what excites me the most about React supporting them natively. Hopefully this means that enzymejs will be able to easily walk down and seamlessly jump into a different part of the DOM without having to use references to adjust.

Portals are helpful when using content overflow in modals. For example, we have a modal which contains a form and that form has an autocomplete text box. When we render the autocomplete part, we need to render it outside of the modal, otherwise the overflow policy blocks the contents and does not allow the autocomplete are to appear over / outside of the modal.

The use of portals also make it easier to support screen readers through the aria tags by allowing the application to quickly block the background of the application and allow the screen reader to focus on the content presented to the user.

Re:React 16 by danield9tqh on Tuesday September 26, 2017 @11:45PM (#15344770)
This does worry me a bit though. There is probably a reason they are difficult to test, because they go against the React DOM pattern of a component only having control over the DOM nodes inside it. Call me a purist but this seems like a deviation from React's functional roots and going against the very problem React was trying to solve in the first place.
Re:React 16 by danabramov on Wednesday September 27, 2017 @06:25AM (#15346371)
The feature is mostly intended for rendering into nodes not managed by React. Such as a document child that is sibling to the application root.
Re:React 16 by maaaats on Wednesday September 27, 2017 @01:53AM (#15345227)
That may be true, but not having this possibility has made react near unusable for a lot of common UI patterns on the web.
Re:React 16 by AgentME on Tuesday September 26, 2017 @02:45PM (#15341460)
The portal API sounds great for modals and dropdowns. It looks like a good fit for react-float-anchor[0] (used by the more interesting to look at react-menu-list[1]). I'm currently abusing `componentWillReceiveProps` to get portal-like behavior, but it means that test code has to do react-float-anchor -specific things in certain situations to see elements rendered in it.

[0] https://github.com/StreakYC/react-float-anchor [1] https://github.com/StreakYC/react-menu-list

Re:React 16 by ryanbertrand on Tuesday September 26, 2017 @12:41PM (#15340301)
We use ad hoc portals for showing modals, flyout panels, popovers.
Re:React 16 by audessuscest on Tuesday September 26, 2017 @01:04PM (#15340529)
Do you know where to find some usage examples ?
Re:React 16 by captnasia on Tuesday September 26, 2017 @01:13PM (#15340617)
If you go to the Portals documentation ( https://facebook.github.io/react/docs/portals.html ) you can find some examples throughout.
Re:React 16 by teraflop on Tuesday September 26, 2017 @01:54PM (#15341013)
Both of the CodePen example links on that page are insidiously broken. The demos appear to work, but they don't actually demonstrate the claimed portal functionality at all:

    // These two containers are siblings in the DOM
    const appContainer = document.getElementById('app-container');
    const modalContainer = document.getElementById('app-container');
Note that both variables refer to the same element.
Re:React 16 by danabramov on Tuesday September 26, 2017 @02:02PM (#15341104)
Sorry, there was so much to do in the release that some issues crept into the new docs. We'll fix them soon. :-)
Re:React 16 by acdlite on Tuesday September 26, 2017 @02:23PM (#15341298)
Fixed now! Thanks for the bug report!
Re:React 16 by teraflop on Tuesday September 26, 2017 @06:37PM (#15343215)
No problem! And on re-reading my comment, I probably shouldn't have used the word "insidiously", it came off a lot more negative than I intended. Thanks for the quick fix.
Re:React 16 by maaaats on Tuesday September 26, 2017 @01:50PM (#15340982)
I've used portals to make modals, as they often have to be close to the root. This has had many quirks and bugs from code not expecting to be in a portal, hopefully it being a supported concept fixes this.