JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Jan 27, 2021 22:33
Cannot read property of undefined
Jan 27, 2021 22:32
{navigationLinks.map((item, index) => {
          return (
            <li key={index} onClick={() => handleClick(item)}>
              {item}
            </li>
          );
        })}
Jan 27, 2021 22:31
How come I can't use the item as a param for my onClick?
Mar 5, 2020 20:36
I'm back guys with improvements since yesterday :) Any idea why this renders so janky on scroll? codesandbox.io/s/sweet-moser-m6ooc
Mar 4, 2020 20:06
I've been searching the web like crazy, can't find a single react example of this path drawing thing
Mar 4, 2020 20:02
Guys, I'm trying to do this animation from w3 school in react, but I'm lost..
Is there some better way? Recomended library?

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_svg_scrolldrawing'

This is what I've got...

https://codesandbox.io/s/admiring-goldberg-39x29
Feb 24, 2020 20:19
ohh :P
Feb 24, 2020 20:18
I did, or I thought I did :(
Feb 24, 2020 20:16
Could this be written in a cleaner way?
Feb 24, 2020 20:16
const hh = hours <= 9 ? `0${hours}` : hours;
const mm = minutes <= 9 ? `0${minutes}` : minutes;
const ss = seconds <= 9 ? `0${seconds}` : seconds;

const time = `${hh}:${mm}:${ss}`;
Sep 21, 2019 17:36
So, can I modify the incoming data, the first one into looking like the second one before adding it to my state array, or should I create another state and modify it in there instead?
Sep 21, 2019 17:36
Nice, thank you :) Had to use an online json formatter for this to work
Sep 21, 2019 17:35
{
    category:"Cars",
    question:"Which one is a car?",
    answers:[
        {
            answer:"Apple",
            isCorrect:false
        },
        {
            answer:"Pizza",
            isCorrect:false
        },
        {
            answer:"Lamp",
            isCorrect:false
        },
        {
            answer:"BMW",
            isCorrect:true
        }
    ]
}
Sep 21, 2019 17:32
Sorry, but I dont know what u on about, im hitting the format button
Sep 21, 2019 17:30
I did hit format button
Sep 21, 2019 17:29
Im making a fetch to an API and get an array of objects as a result, can I modify this before adding it to my react state, or do I add it to the state, and then create another state for the modified objects?
Aug 6, 2019 21:36
Boy do I feel stupid now, thank you :)
Aug 6, 2019 21:34
Any tips on how I could write this "custom made" radio buttons in a cleaner way?
Aug 6, 2019 21:34
  handleFemaleClick = () => {
    this.setState({ gender: 1, femaleSelected: true, maleSelected: false });
  }

  handleMaleClick = () => {
    this.setState({ gender: 2, femaleSelected: false, maleSelected: true });
  }

<button onClick={() => this.handleFemaleClick()} style={{ background: this.state.femaleSelected ? 'red' : 'green' }}>Female</button>
<button onClick={() => this.handleMaleClick()} style={{ background: this.state.maleSelected ? 'red' : 'green' }}>Male</button>
Apr 1, 2019 18:54
:D
Apr 1, 2019 18:53
wow, coming up with another name for "res" was quite hard
Apr 1, 2019 18:49
response ofcourse!
Apr 1, 2019 18:47
That makes sense, you are awesome @rlemon :)
Apr 1, 2019 18:46
Now I see :D So I should change .then(res.... to .then(result etc?
Apr 1, 2019 18:45
Ohhhhh
Apr 1, 2019 18:45
So the res is not actually res?
Apr 1, 2019 18:44
app.post("/name", (req, res) => {
  const data = new Data({
    id: req.body.id,
    name: req.body.name
  });

  data
    .save()
    .then(res => {
      res.status(201).json({ body: data });
    })
    .catch(err => {
      res.status(500).json({ error: err });
    });
});
Apr 1, 2019 18:44
Ohh not sure I understand
Apr 1, 2019 18:41
any ideas?
Apr 1, 2019 18:41
tryed using, .then(function (res) {.....}) with no luck
Apr 1, 2019 18:40
TypeError: res.status is not a function
Apr 1, 2019 18:40
  data
    .save()
    .then(res => {
      res.status(201).json({ body: data });
    })
    .catch(err => {
      res.status(500).json({ error: err });
    });
Mar 31, 2019 16:00
Ahh nvm, gotta find another way I belive
Mar 31, 2019 16:00
Reversing my order every letter I type in the forms input field
Mar 31, 2019 16:00
using .reverse() not really doing it
Mar 31, 2019 15:59
Very nice :) How would I do to make sure that item renders first?
Mar 31, 2019 15:56
Works like a charm, thank you :)
Mar 31, 2019 15:56
link === history[history.length - 1] ? <p>{link.shortId}</p> : <p>{link.url}</p>
Mar 31, 2019 15:56
Oh cool, like;
Mar 31, 2019 15:55
but how would I check if link is the last one?
Mar 31, 2019 15:55
const { history } = this.state;
    const renderHistory = history.map(link => {
      return (
        history[history.length - 1] ? <p>{link.shortId}</p> : <p>{link.url}</p>
      );
    });
Mar 31, 2019 15:54
yeah sorry, it was actually like this
Mar 31, 2019 15:51
its the last item every time it maps?
Mar 31, 2019 15:50
const renderHistory = this.state.history.map(link => {
  return (
    history[history.length - 1] ? <p>{link.shortId}</p> : <p>{link.url}</p>
  );
});
Mar 31, 2019 15:50
Why is this not working?
Mar 31, 2019 12:43
What does that mean? Should it remember when closing the browser and opening it back up?
Mar 31, 2019 12:42
"The application should remember searches between browser sessions."
Mar 31, 2019 12:29
Sorry, wrong port.. Ill stop asking stupid questions now :)
 

Trash can

Like the recycle bin, but trashier.
Sep 21, 2019 17:31
{
category: "Cars",
question: "Which one is a car?",
wrong_answers: ["Apple", "Pizza", "Lamp"],
right_answer: "BMW"
}
Sep 21, 2019 17:30
This is what I get,
{
category: "Cars",
question: "Which one is a car?",
wrong_answers: ["Apple", "Pizza", "Lamp"],
right_answer: "BMW"
}