NineCattoRules

JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Jan 30, 2023 10:17
Hi, 2 things I would like to see implemented in SO are: 1 - button x fullscreen mode x view wrapped embed code (useful x small screen), 2 - a simple button to copy the content of embed code
Jan 10, 2023 15:47
@JBis from useContext
Jan 10, 2023 14:13
What I can do is take the variable directly from the DOM...but I don't know if that's the best solution
Jan 10, 2023 13:51
from scrollHandler function I cannot use any context variables 'cause are undefined
Jan 10, 2023 13:50
main.addEventListener('scroll', scrollHandler);
Jan 10, 2023 13:50
Dear,
can someone explain to me how do i use a context variable by calling a function from an event listener?
In useEffect I do this:
Jan 2, 2023 17:47
@VLAZ Damn! Exactly, thanks!
Jan 2, 2023 09:47
0_0
Jan 2, 2023 09:46
instead of .value, how could I add a variable?
Jan 2, 2023 09:46
export const arrSort = (arr) => {
    arr.sort((a, b) => parseFloat(a.value) - parseFloat(b.value));
}
Jan 2, 2023 09:46
Hi all, I feel dumb to ask this but... in this scenario:
Sep 17, 2022 18:55
I just need a counter that don't rerender on items moves.
Sep 17, 2022 18:52
Draggable basically allows me to move divs in a list...but the index always remain the same, so if I move div0 to div1 index 0 still be in the same position (at div0). Is there a way to keep as prop the initial key given (to pass as prop in Formsong component)? So if I move div0 to div1 the map should be this: div1 (index=1) div0 (index=0)
Sep 17, 2022 18:44
fields.map((name, index) => (
    <Draggable
        key={index}
        index={index}
    >
        <Formsong
            index={index}
            name={name}
            values={props.values}
        />
    </Draggable>
))
Sep 17, 2022 18:43
Hi everyone, in my code below I have a react sortable component:
Sep 7, 2022 16:08
@KarelG :)
Sep 7, 2022 12:49
of course, thanks!
Sep 7, 2022 12:48
so basically this should be enough: observer.current.unobserve(elRef.current);
Sep 7, 2022 12:46
and at first sight I thought it was related to this stackoverflow.com/a/71222907/4458531
Sep 7, 2022 12:44
@KarelG I see...I took that snippet from this tut: blog.sethcorker.com/resize-observer-api
Sep 7, 2022 12:29
what I don't understand is why this happens since useEffect hook is like $(document).ready(function()
Sep 7, 2022 12:18
it only display when I change something in the code (and Next JS does a fast reload)
Sep 7, 2022 12:17
@Cerbrus when I manually reload the page this error disappear
Sep 7, 2022 12:11
Should I use an async function?
Sep 7, 2022 12:10
const observer = React.useRef(
    new ResizeObserver(entries => {
        const { width } = entries[0].contentRect;

        setWidth(width)
    })
);

React.useEffect(() => {
    if (elRef != null && elRef.current) {
        if (observer != null && observer.current) {
            observer.current.observe(elRef.current);

            return () => {
                observer.current.unobserve();
            };
        }

    }

}, [elRef, observer]);
Sep 7, 2022 12:09
Hi all, I can't get rid off this error "Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present" ...here below my code:
Sep 4, 2022 08:21
I love Stackoverflow, pretty much everything I know about programming I learned self-taught here. Big ♥
Aug 20, 2022 18:44
const groupBy = (x, f) => x.reduce((a, b) => ((a[f(b)] ||= []).push(b), a), {});
Aug 20, 2022 18:44
I end up using this:
Aug 20, 2022 11:21
After many tries I'm not able to find a right solution...I believe I must use .reduce, but how, it's difficult to find a good example somewhere on the web
Aug 20, 2022 11:18
single arrays grouped by date (x)
Aug 20, 2022 11:17
[
    [
        [
            {
                "x": "8/9/2022",
                "y": 0.43
            }
        ],

        [
            {
                "x": "8/15/2022",
                "y": 0.63
            }
        ],
    ],
    [
        [
            {
                "x": "8/9/2022",
                "y": 0.5
            },
            {
                "x": "8/9/2022",
                "y": 0.2
            }
        ],
        [
            {
                "x": "8/11/2022",
                "y": 0.7
Aug 20, 2022 11:17
What's a good way to achieve this:
Aug 20, 2022 11:16
let data = [
    [
        {
            "x": "8/9/2022",
            "y": 0.43
        },
        {
            "x": "8/15/2022",
            "y": 0.63
        }
    ],
    [
        {
            "x": "8/9/2022",
            "y": 0.5
        },
        {
            "x": "8/9/2022",
            "y": 0.2
        },
        {
            "x": "8/11/2022",
            "y": 0.7
        }
    ]
]
Aug 20, 2022 11:16
Hello everyone, I need some help here. My array looks like this:
Aug 18, 2022 12:11
what I used is .get("a484075a-6920-4f13-ad18-203b64dc4f90") ...so now I can loop the array...
Aug 18, 2022 11:45
{
    "a484075a-6920-4f13-ad18-203b64dc4f90": [
        {
            "price": 0.43,
            "createdAt": "2022-08-09T16:40:28.806Z",
            "regionid": "a484075a-6920-4f13-ad18-203b64dc4f90"
        },
        {
            "price": 0.63,
            "createdAt": "2022-08-15T16:40:28.806Z",
            "regionid": "a484075a-6920-4f13-ad18-203b64dc4f90"
        }
    ],
    "402608fd-81be-4fd6-8c70-70692d6267da": [
        {
            "price": 0.5,
            "createdAt": "2022-08-09T16:40:28.806Z",
Aug 18, 2022 11:44
Hi all, how could I map this JSON?
Jun 18, 2022 11:48
books.filter(e => e !== undefined).map((obj, index) etc...
Jun 18, 2022 11:47
I end up with this:
Jun 18, 2022 09:27
unlike this give me error "TypeError: Cannot read properties of undefined (reading 'item')
Jun 18, 2022 09:26
books?.map((obj, index) => {
    if (index === 0) obj.item?[0].id = index + 1;
    return obj;
});
Jun 18, 2022 09:26
I tried this:
Jun 18, 2022 09:23
how can I skip undefined arrays on object?
Jun 18, 2022 09:22
so the problem is this...if I map through "books", since "item" is dinamically, at the start is undefined
Jun 18, 2022 09:20
"books": [
    {
        "item": [
            {
                "title": "Any reason for hate you",
                "preview": "blob:localhost:3000/da032196-27f9-40a8-a300-836bb0431a80";
            }
        ]
    },
    {
        "item": [
            {
                "title": "Why am I doing this?",
                "preview": "blob:localhost:3000/e0b7562a-cd5a-4a9a-8d72-a38a23025ed7";
            }
        ]
    }
]
Jun 18, 2022 09:20
Dear all, I'm having trouble with React JS...
Jun 17, 2022 11:59
it was because 'name' was already set as variable!
Jun 17, 2022 11:58
arghhhh
Jun 17, 2022 11:56
what the heck