These are chat archives for FreeCodeCamp/Help

8th
Mar 2019
kinopotato
@kinopotato
Mar 08 02:33
hello, can I ask a quick question with CSS?
so I have 4 elements inside a wrapper div with flex display, basically 4 blocks. 1 <h1> and 3 <div>
I gave my <h1> element width: 100%, but instead of pushing the other 3 divs down in a new line, it just pushes them all to the right :|
Normally to solve this, I would wrap my h1 inside another div, but there must be a more straightforward solution right?
Christopher McCormack
@cmccormack
Mar 08 02:52
@kinopotato did you add flex-wrap?
kinopotato
@kinopotato
Mar 08 02:52
no, I forgot what that does. lemme try :D
Luc Martin
@fmartin5
Mar 08 02:52
@kinopotato Did you set flex-direction: column to your wrapper div ? It has been a while since I did CSS, but I think otherwise you will get a row no matter what, and width:100% will not help
kinopotato
@kinopotato
Mar 08 02:53
@fmartin5 I don't want it to be column because the other 3 should be in a single line
Luc Martin
@fmartin5
Mar 08 02:53
Oh ok alright then :)
Aditya
@ezioda004
Mar 08 02:53
Sounds like you're missing flex-wrap: wrap;
kinopotato
@kinopotato
Mar 08 02:54
well that worked :|
thanks @cmccormack @ezioda004 !
Christopher McCormack
@cmccormack
Mar 08 02:58
:thumbsup:
Christopher McCormack
@cmccormack
Mar 08 03:05
@ezioda004 yo you still around?
Aditya
@ezioda004
Mar 08 03:06
@cmccormack Yes sir
Christopher McCormack
@cmccormack
Mar 08 03:06
I have an ugly block of code, wondering if there's a better way...
I'm making a small app to migrate from a CSV file to another CSV file with different/additional fields, where the new one basically updates what it can from the old then lets you fill in the rest
Luc Martin
@fmartin5
Mar 08 03:06
I have more than one of them :laughing:
Christopher McCormack
@cmccormack
Mar 08 03:06
lol
I'm putting my state in a hook:
  const [files, setFiles] = useState([
    { name: "file1", title: "Current Template", csv: "", json: "" },
    { name: "file2", title: "New Template", csv: "", json: "" },
  ]);
but my callback function that I send to the file picker is not great:
        setFiles([
          i === 0 ? Object.assign(files[0], { csv: results }) : files[0],
          i === 1 ? Object.assign(files[1], { csv: results }) : files[1],
        ]);
I basically have to send an index value back from the input element using onChange={handleFile.bind(null, i)} so I know which one to update
know a better way?
I feel there must be a cleaner way to do the state and the state updater but not yet sure
Aditya
@ezioda004
Mar 08 03:13
Hmm, why do you have 2 objects in the state? Cant you use one? (have a generic object template and reuse it)
Christopher McCormack
@cmccormack
Mar 08 03:15
yeah I started with that but turned it into an array so I could map over it in the view component, I guess I could map over the keys instead
Luc Martin
@fmartin5
Mar 08 03:15
        if(i === 0 || i === 1)  Object.assign(files[i], { csv: results });
        setFiles([
          files[0],
          files[1],
        ]);
Would this help? Sorry I'm not sure what can be the values of i
It can become simpler if you only ever have two files
Christopher McCormack
@cmccormack
Mar 08 03:17
Yeah I do only ever have 2
Aditya
@ezioda004
Mar 08 03:17
You'd also have to assign the value from Object.assign then
Christopher McCormack
@cmccormack
Mar 08 03:19
@ezioda004 not sure what you mean sorry
Aditya
@ezioda004
Mar 08 03:20
Oh I meant in the above example by @fmartin5
Since Object.assign returns a new object
Christopher McCormack
@cmccormack
Mar 08 03:20
hah I was actually about to ask that exact question
Luc Martin
@fmartin5
Mar 08 03:21
Object.assign(files[i], { csv: results });
setFiles(files);
Assuming files is an Array
Aditya
@ezioda004
Mar 08 03:21
@cmccormack I usually use Object.entries to map over key: value pair, its a handy method and works well with react
Christopher McCormack
@cmccormack
Mar 08 03:22
yeah I keep flip-flopping on how to do this
what's kind of strange, I just noticed, is that if I try to change the file for a second time, my useEffect doesn't work (logging the files), if I use the same file, but if I use a different file, it works every time
Luc Martin
@fmartin5
Mar 08 03:23
@ezioda004 Does not Object.assign modify its argument in-place then return it ?
Christopher McCormack
@cmccormack
Mar 08 03:23
I tried spreading the whole thing to build a new object but that didn't fix it, seems odd to me
        setFiles([
          i === 0 ? Object.assign(files[0], { csv: results }) : { ...files[0] },
          i === 1 ? Object.assign(files[1], { csv: results }) : { ...files[1] },
        ]);
hmm which tool is best to quickly import from github so I can share this?
Luc Martin
@fmartin5
Mar 08 03:24
Why not just files[i].csv = results
Aditya
@ezioda004
Mar 08 03:24
@fmartin5 It does modify and return, but doesnt mutate, you'd have to assign to some variable to keep the modified result
Christopher McCormack
@cmccormack
Mar 08 03:24
@fmartin5 I wanted a new array so react sees them as different objects
Aditya
@ezioda004
Mar 08 03:25
@cmccormack ctrl c => ctrl v
Christopher McCormack
@cmccormack
Mar 08 03:25
hah no I mean the whole thing
like import from github and have it running quickly
but also see the code easily
Aditya
@ezioda004
Mar 08 03:25
ctrl a => ctrl c => ctrl v :D
Luc Martin
@fmartin5
Mar 08 03:25
@cmccormack Then you could use Array.from to copy the array
Or [...files]
Aditya
@ezioda004
Mar 08 03:26
@cmccormack I think codesandbox have an option to import from github? I could be wrong but I remember seeing something like that
Christopher McCormack
@cmccormack
Mar 08 03:27
yup you're right testing it now
I have to say that is pretty badass
that may be the fastest I ever got something to work
not sure if you have readily available CSV file but if you load the same file twice you won't see it log from the useEffect
Luc Martin
@fmartin5
Mar 08 03:30
@ezioda004 It seems to mutate things for me, e.g.
Node.js> const obj = {};
Node.js> Object.assign(obj,{foo: 42});
Node.js> console.log(obj);
{ foo: 42 }
I could keep the modified object without making a new variable
Christopher McCormack
@cmccormack
Mar 08 03:32
ah I just realized why selecting the same file doesn't trigger the useEffect, it's probably not invoking the onChange handler of the input /duh
OK you guys have given me some good info, I may switch this to an object of objects and try it
Aditya
@ezioda004
Mar 08 03:33
@fmartin5 Yeah you right, I forgot the first argument is the target obj which it copies stuff over
Christopher McCormack
@cmccormack
Mar 08 03:35
does the useState setter method always invoke a rerender even if the shallow comparison shows the same reference or value?
Luc Martin
@fmartin5
Mar 08 03:35
Yeah it's not as functional as in other languages
Aditya
@ezioda004
Mar 08 03:38
@cmccormack I'm guessing yeah, by default it's showComponentUpdate => true
Christopher McCormack
@cmccormack
Mar 08 03:39
but that's only on render right? does the setter method always force a rerender?
or is that what you meant?
Aditya
@ezioda004
Mar 08 03:49
@cmccormack Seems like you need to reset the value of the input file each time on click, otherwise it caches
Christopher McCormack
@cmccormack
Mar 08 03:50
:/
I'll keep playing with it, thank you @ezioda004 @fmartin5 !
going to go do something else for a bit, have a good night/day
Luc Martin
@fmartin5
Mar 08 03:51
:smile:
Aditya
@ezioda004
Mar 08 03:52
@cmccormack See ya, btw this might work onClick={e => e.target.value = null}source
Christopher McCormack
@cmccormack
Mar 08 03:53
@ezioda004 oh that's perfect, kind of what I was thinking as well, although I wasn't sure what the property is
Thanks man
Aditya
@ezioda004
Mar 08 03:53
:sparkles:
kinopotato
@kinopotato
Mar 08 06:22
any pro tip on how to make static websites look pro?
abraham anak agung
@padunk
Mar 08 08:05
@kinopotato I sometimes visit https://www.awwwards.com/ for inspiration
kinopotato
@kinopotato
Mar 08 09:50
I suddenly remember someone saying that the best looking websites are seldom seo'd is this true??
@padunk this is really great for inspiration :D
Niraj Nandish
@Nirajn2311
Mar 08 10:09
@diomed are you on discord
BuntyBru
@BuntyBru
Mar 08 10:25
in case of .map(res => res.json())
res is now in json format right ?
whereas
```
.map(res =>
{res.json()
})
res is not in Json format
right?
fajar12345
@fajar12345
Mar 08 13:06
does anyone here know what the matters is ,

// Initialize these three variables
var a;6
var b;15
var c;I am a String!";

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c + " String!";

i can't rude those code
run
rupali317
@rupali317
Mar 08 13:07
var a = 6;
var b = 15;
var c = "I am a String!";
fajar12345
@fajar12345
Mar 08 13:10
it doesn't work yet
i've already figured it out thanks for helping me
BuntyBru
@BuntyBru
Mar 08 13:21
Hi guys ,
so here is the thing
totalpages=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
(15) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
doubleArray = Math.ceil(totalpages.length/6)
3

totalpagesArray =[]

for( var i=0;i<doubleArray;i++)
{
    totalpagesArray.push(new Array())
}
3
totalpagesArray
(3) [Array(0), Array(0), Array(0)]
t1 =0

s=6

t2 = s+t1

for(var i=0;i<totalpagesArray.length;i++){
    for(var j=t1;j<t2;j++){
        totalpagesArray[i].push(totalpages[j])
    }
if( s+t1 < totalpages.length){
t1=t2
t2=s+t1
}
else{
t1=t2
t2 = (s+t1)-totalpages.length
}}
kinopotato
@kinopotato
Mar 08 13:21
Hello, can someone take a look at this static codepen page I'm making? It's loading really slow for me and I just wanted to know if it also loads and scrolls slow for you
https://codepen.io/kinopotato/full/rRmemL
BuntyBru
@BuntyBru
Mar 08 13:27
Hi guys ,
so here is the thing
totalpages=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
(15) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
doubleArray = Math.ceil(totalpages.length/6)
3

totalpagesArray =[]

for( var i=0;i<doubleArray;i++)
{
    totalpagesArray.push(new Array())
}
3
totalpagesArray
(3) [Array(0), Array(0), Array(0)]
t1 =0

s=6

t2 = s+t1

for(var i=0;i<totalpagesArray.length;i++){
    for(var j=t1;j<t2;j++){
        totalpagesArray[i].push(totalpages[j])
    }
if( s+t1 < totalpages.length){
t1=t2
t2=s+t1
}
else{
t1=t2
t2 = (s+t1)-totalpages.length
}}
i wanted totalpagesArray = [[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15]]

But i am getting 
 [[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,undefined,undefined,undefined]]
idris
@idris12
Mar 08 14:03
Hi when ever i open my index page with live server it opens my background image like so
tax.PNG
But when i open the html normally from the folder it shows this why is that
bg-2.PNG
kinopotato
@kinopotato
Mar 08 14:26
anyone got any idea why this is so slow in codepen? it's literally html/css right now
idris
@idris12
Mar 08 14:29
@kinopotato it works perfectly for me
kinopotato
@kinopotato
Mar 08 14:29
doesn't scroll slow?
idris
@idris12
Mar 08 14:33
nope it scrolls very fast actually
kinopotato
@kinopotato
Mar 08 14:33
I deployed it locally and it's fine but it really doesn't work in codepen for me and for another device O.O
well thanks for checking it out @idris12 :) I appreciate it, at least now I know it's not codepen for sure.
idris
@idris12
Mar 08 14:35
@kinopotato any time
am also having an issue when i open my code with live server my background image shows but when i open it locally it doesnt
dociledevil
@dociledevil
Mar 08 14:46
Hey.. I am facing an issue with one of the exercises in EC6 section for Javascript tutorial

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-rest-operator-with-function-parameters/ is the exercise. what I cant understand is after completing the exercise, my code is
const sum = (function() {
"use strict";
return function sum(...arr) {
const args = arr;
return args.reduce((a, b) => a + b, 0);
};
})();
console.log(sum(1, 2, 3)); // 6

But I am still not checking the item The sum function uses the ... spread operator on the args parameter.

I am using the spread operator and not the spread operator here.
dociledevil
@dociledevil
Mar 08 14:54
rest*
May Kittens Devour Your Soul
@diomed
Mar 08 15:02
@Nirajn2311 all day long
Niraj Nandish
@Nirajn2311
Mar 08 15:18
@diomed nice, whats your discord id
Aditya
@ezioda004
Mar 08 16:39
@dociledevil In function sum(...arr), the ...arr is not spread operator but the opposite of it, called rest parameter
yj
@atangyj
Mar 08 17:24
Hi all, I have a question about layout in React. What's a better way to layout components on a screen? Will you wrap each component by div and styling the div in the screen component's cs file to control the position? Or control the position in the component's own css file?
Christopher McCormack
@cmccormack
Mar 08 17:28
in the end React is going to render the same type of elements you use with normal html/css, so style it the way you would without it
as to where to put the file, I like to use an scss file per component, but it's up to you
Styled components are nice, as is JSS
May Kittens Devour Your Soul
@diomed
Mar 08 17:29
@cmccormack u up for a hangman?
Christopher McCormack
@cmccormack
Mar 08 17:31
Sure!
May Kittens Devour Your Soul
@diomed
Mar 08 17:32
_ _ _ _ _ _ A T _ _ _
@Nirajn2311 have u taken a look @ vue materials?
Christopher McCormack
@cmccormack
Mar 08 17:34
C
May Kittens Devour Your Soul
@diomed
Mar 08 17:34
no C
Christopher McCormack
@cmccormack
Mar 08 17:35
I give up!
too hard
H
May Kittens Devour Your Soul
@diomed
Mar 08 17:36
no H
Niraj Nandish
@Nirajn2311
Mar 08 17:40
@diomed I have my finals going on now
So I ain't touching computer related stuff till 18 march
Christopher McCormack
@cmccormack
Mar 08 17:40
G
May Kittens Devour Your Soul
@diomed
Mar 08 17:40
ugh... when's it gonna stop
Niraj Nandish
@Nirajn2311
Mar 08 17:40
Shit I missed hangman today
May Kittens Devour Your Soul
@diomed
Mar 08 17:40
no _ G
you didnt miss it, it's in progress @Nirajn2311
Niraj Nandish
@Nirajn2311
Mar 08 17:41
I haven't touched Vue for 4 months
May Kittens Devour Your Soul
@diomed
Mar 08 17:42
._.
you're young, u still have time
Christopher McCormack
@cmccormack
Mar 08 17:43
S
May Kittens Devour Your Soul
@diomed
Mar 08 17:43
no_S
Christopher McCormack
@cmccormack
Mar 08 17:44
oh come on!
R
May Kittens Devour Your Soul
@diomed
Mar 08 17:45
_ _ R _ _ R A T _ _ _
lol
Christopher McCormack
@cmccormack
Mar 08 17:46
D
May Kittens Devour Your Soul
@diomed
Mar 08 17:46
now I wonder did he see it
no_D
yj
@atangyj
Mar 08 17:48
@cmccormack Thanks. I use style file for each component too. My problem is when combining several components for a page, how do you control their positions relative to each other?
Isn’t it hard if doing in on component’s own file?
Christopher McCormack
@cmccormack
Mar 08 17:50
See what?
T
May Kittens Devour Your Soul
@diomed
Mar 08 17:51
it's there
Christopher McCormack
@cmccormack
Mar 08 18:00
bah
i dumb
H
May Kittens Devour Your Soul
@diomed
Mar 08 18:00
no H
Christopher McCormack
@cmccormack
Mar 08 18:01
@atangyj you should configure that in the parent component, just like you would use a parent selector to define it's internal layout
yj
@atangyj
Mar 08 18:02
@cmccormack i see
thanks
Kaz Baig
@kbaig
Mar 08 18:05
@atangyj that's why I like styled components. I can define the styles for each component in its own file, and then override it in the parent component file for positioning
Niraj Nandish
@Nirajn2311
Mar 08 18:08
@diomed did Chris solve it yet
May Kittens Devour Your Soul
@diomed
Mar 08 18:12
no, not yet.
he's not in the mood today, I sense it
@Nirajn2311
_ _ R _ _ R A T _ _ _
Christopher McCormack
@cmccormack
Mar 08 18:14
hah sorry work keeps pulling me in
also it's not satisfying being rejected
May Kittens Devour Your Soul
@diomed
Mar 08 18:15
I dont reject you
Niraj Nandish
@Nirajn2311
Mar 08 18:16
S
Christopher McCormack
@cmccormack
Mar 08 18:16
B
May Kittens Devour Your Soul
@diomed
Mar 08 18:16
oh noeS
no B
such a cursed word
Niraj Nandish
@Nirajn2311
Mar 08 18:19
C
May Kittens Devour Your Soul
@diomed
Mar 08 18:19
not even C
Niraj Nandish
@Nirajn2311
Mar 08 18:23
D
Christopher McCormack
@cmccormack
Mar 08 18:23
Y am I still guessing!
May Kittens Devour Your Soul
@diomed
Mar 08 18:24
no to both
Niraj Nandish
@Nirajn2311
Mar 08 18:24
Hoping that one day the answer will reveal itself to us
May Kittens Devour Your Soul
@diomed
Mar 08 18:24
:smile_cat:
Niraj Nandish
@Nirajn2311
Mar 08 18:24
E
Christopher McCormack
@cmccormack
Mar 08 18:24
F
May Kittens Devour Your Soul
@diomed
Mar 08 18:24
not even once
Christopher McCormack
@cmccormack
Mar 08 18:24
going to need an already guessed line added to that app
May Kittens Devour Your Soul
@diomed
Mar 08 18:25
it's tricky coz it's repeating
Niraj Nandish
@Nirajn2311
Mar 08 18:25
Give topic hint
May Kittens Devour Your Soul
@diomed
Mar 08 18:25
it's a phenomenon :D
Niraj Nandish
@Nirajn2311
Mar 08 18:26
Scientific or natural
May Kittens Devour Your Soul
@diomed
Mar 08 18:26
natural
Niraj Nandish
@Nirajn2311
Mar 08 18:27
Ill come back at 12
and finish solving it
May Kittens Devour Your Soul
@diomed
Mar 08 18:27
._.
I'm asleep then
unless... what time is that for me
dunno your time
Christopher McCormack
@cmccormack
Mar 08 18:29
G
May Kittens Devour Your Soul
@diomed
Mar 08 18:30
no G
gee whiz
Christopher McCormack
@cmccormack
Mar 08 18:37
J?
this is actually impossible
May Kittens Devour Your Soul
@diomed
Mar 08 18:38
no J
great word . lol
Christopher McCormack
@cmccormack
Mar 08 18:41
L
May Kittens Devour Your Soul
@diomed
Mar 08 18:41
no L, but possibility of close letters to it
real chance in fact
like, over 90%
Christopher McCormack
@cmccormack
Mar 08 18:46
M~
May Kittens Devour Your Soul
@diomed
Mar 08 18:47
yup
M _ R M _ R A T _ _ _
Christopher McCormack
@cmccormack
Mar 08 18:49
N
May Kittens Devour Your Soul
@diomed
Mar 08 18:51
yes
M _ R M _ R A T _ _ N
care to guess?
Christopher McCormack
@cmccormack
Mar 08 18:51
MURMURATION?
May Kittens Devour Your Soul
@diomed
Mar 08 18:51
:ballot_box_with_check:
:congratulations: correct!
Christopher McCormack
@cmccormack
Mar 08 18:52
what izzit?
woohoo!
May Kittens Devour Your Soul
@diomed
Mar 08 18:52
flock of starlings is called a murmuration
Christopher McCormack
@cmccormack
Mar 08 18:52
of course a cat would use a word about birds
May Kittens Devour Your Soul
@diomed
Mar 08 18:53
haha
Christopher McCormack
@cmccormack
Mar 08 18:54
The sesquipedalian murmuration evokes the kitten's perspiration
@diomed thanks for the game!
May Kittens Devour Your Soul
@diomed
Mar 08 18:56
coming up next: codswallop, poppycock, and balderdash...
stay tuned :smile:
wait! ... damnit!
Christopher McCormack
@cmccormack
Mar 08 18:58
so esoteric
May Kittens Devour Your Soul
@diomed
Mar 08 19:00
@cmccormack here's today's reward
Christopher McCormack
@cmccormack
Mar 08 19:00
That is one handsome doggo
thanks!
zootechdrum
@zootechdrum
Mar 08 20:02
hello, I have a question. I am trying to show an alert if the user was successfully registered or display an alert if there was an error
I am having a hard time trying to figure this out
here is the code I have so far
app.use("/public", express.static(path.join(__dirname, 'public')));

app.get('/', (req,res) => {
    res.sendFile(path.join(__dirname + '/index.html'))
})

app.post('/register', function(req,res){
    const person = {
            email_id:req.body.email,
            name: req.body.name,
            message:req.body.message
    };
//MySQL code that will insert info in to userTable
    connection.query('INSERT INTO userTable SET ?', person, (err, result) => {
        if(err){
            app.get('/', (req, res) => {
                alert("something went wrong");
            })

        }
        console.log("it was a sucess")
    })
})
Jason Luboff
@JLuboff
Mar 08 20:13
Use something like express-flash or send back an alert/status to the front end to then display the alert
Niraj Nandish
@Nirajn2311
Mar 08 20:53
@diomed you're 3 hours behind me
idris
@idris12
Mar 08 21:02
Hi so am trying to solve a coding challenge where
if a>b alice gets one point
if b>a bob gets one point
but is a=b alice and bob doesnt get a point
so far the points are not adding up and its giving me weird result heres the code pen
Bjorn van de Peut
@bjorno43
Mar 08 21:09
@idris12 Remove your last else if part. Since neither gets anything, you don't have to do anything. By using alice+= " " you're trying to add a string to an integer. A space character to a number. That's not possible. If you don't want to add anything, you do += 0 or just don't do it
idris
@idris12
Mar 08 21:13
@bjorno43 you a life saver i was scratching my head for hours wondering what i was doing wrong thank you
Bjorn van de Peut
@bjorno43
Mar 08 21:14
No problem :)
Christopher McCormack
@cmccormack
Mar 08 21:19
@bjorno43 yo how you been?
Bjorn van de Peut
@bjorno43
Mar 08 21:26
@cmccormack Long story, unfortunetely I don't have the time to go into detail about it all right now. But I'll become a bit more active again so if I catch you next time we'll have a chat :)
Christopher McCormack
@cmccormack
Mar 08 21:26
no worries man stay safe and healthy and hope to see you when you have more time
Bjorn van de Peut
@bjorno43
Mar 08 21:26
Sure m8, cya
Christopher McCormack
@cmccormack
Mar 08 21:26
see ya
Aditya
@ezioda004
Mar 08 21:56
@cmccormack Heya, you here?
Christopher McCormack
@cmccormack
Mar 08 21:56
yessir, bout to test out the docker version of the local repo
Aditya
@ezioda004
Mar 08 21:59
Do you know why this doesnt work in React?
class App extends Component {
  static anotherStaticMethod() {
  }
  static getDerivedStateFromProps(){
    if (someCondition) {
      this.anotherStaticMethod(); // error
    }
  }
}
Jason Luboff
@JLuboff
Mar 08 22:01
Whats the error? Can't find the method?
Aditya
@ezioda004
Mar 08 22:01
Even though you can call another static method via this in regular JS:
class A {
  static x(){
    console.log("hello world");
  }
  static y(){
    this.x();
  }
}
A.y(); // works
@JLuboff this is returning as undefined in the static method
Although I can do App.anotherStaticMethod() just fine
Christopher McCormack
@cmccormack
Mar 08 22:03
I thought it was because the method is only on the class itself
not on the instance
isn't that what statics are?
Aditya
@ezioda004
Mar 08 22:03
Yeah
But this inside the static method refers to the class itself
According to MDN atleast
Christopher McCormack
@cmccormack
Mar 08 22:04
but you didn't instantiate the second example
You called it directly
Aditya
@ezioda004
Mar 08 22:05
Christopher McCormack
@cmccormack
Mar 08 22:05
right but your first example is an instance right?
meh I'm not sure
Aditya
@ezioda004
Mar 08 22:06
Hmm, does react call the static method from instance?
For example getDerivedStateFromPropssince thats a static method
Christopher McCormack
@cmccormack
Mar 08 22:08
It must right?
because you could have multiple instances using <><App/><App/></> or whatever
each of those has access to that static method
oh wait I lost track of your original question lol
Aditya
@ezioda004
Mar 08 22:12
Its just weird, even if they are calling from instance it should still work:
new A().constructor.y(); // hello world
/shrug
I'll just do App.anotherStaticMethod();
Actually saving 1 char by not using this!
Christopher McCormack
@cmccormack
Mar 08 22:13
@ezioda004 hmm I think this is because of the instance still, the example you are showing is still talking to the class directly
oh did new work?
does new A().y(); work?
I bet it doesn't
Aditya
@ezioda004
Mar 08 22:14
Nope
Christopher McCormack
@cmccormack
Mar 08 22:15
the App. way seems nicer too as it's not ambiguous
Aditya
@ezioda004
Mar 08 22:17
Actually true
Christopher McCormack
@cmccormack
Mar 08 22:18
I never really find myself needing static methods, I should try to use them more. What are you using it for @ezioda004 ?
Aditya
@ezioda004
Mar 08 22:21
@cmccormack I use them often for doing tasks that are not concerned to the instance, like data calculation; currently I'm trying to spawn a worker thread from that method to ease off some calculations and have it on another thread so it doesnt slow down the main thread
Christopher McCormack
@cmccormack
Mar 08 22:22
I guess it's cleaner than referencing an external util method or something, especially if only used in that class
Aditya
@ezioda004
Mar 08 22:24
Yeah its not a whole lot of logic so I thought it should be fine and yeah its only used in that class
Christopher McCormack
@cmccormack
Mar 08 22:26
very cool I'll try to find uses :)
Aditya
@ezioda004
Mar 08 22:26
But you've gone to the hook side! :disappointed:
Christopher McCormack
@cmccormack
Mar 08 22:27
oh yeah
haha
well not yet
I"ve only played with it, no full fledged app using it
sometimes I've gotten close to wanting to jump back
some things are weird, like setting state is more dangerous now
i liked how setState managed it
Aditya
@ezioda004
Mar 08 22:29
I've yet to fully embrace it, sadly I dont think I could advocate it at work any time soon
People dont like change lol