Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    odin-bot
    @odin-bot
    Woot! @codyloyd now has 1533 points
    Andy
    @mindovermiles262
    handleLogout(e) {
        e.preventDefault();
        let that = this
    is let that = this common in react? I don't see that being used anywhere else in the example I'm looking at

    oops

        let that = this
        let email = this.props.currentUser
        axios.delete('/users/sign_out', {
        })
        .then(function(response){
          that.props.changePage("login")
        })

    it looks like that is used in the async/await. Is this common in JS?

    Cody Loyd
    @codyloyd
    yeah that's a thing
    maybe not SUPER common
    Andy
    @mindovermiles262
    Just a way of making it easier to read?
    Cody Loyd
    @codyloyd
    basically if you're making a function that might redefine this and you need to keep a reference to it
    Rhys
    @105ron
    I think it was common before ES6 arrow functions?
    Briggs Elsperger
    @I3uckwheat
    ^^
    Cody Loyd
    @codyloyd
    in this case since they aren't .binding it `this would be different there
    yep
    Rhys
    @105ron
    const { currentUser, email } = this.props
    Andy
    @mindovermiles262
    ahh so it's mostly been replaced by es6
    Rhys
    @105ron
    Use destructuring for your props and state, it's sexy
    Cody Loyd
    @codyloyd
    right there are other ways of doing it
    but still kinda common
    Rhys
    @105ron
    Pamela Anderson sexy
    Javier M
    @Javier-Machin
    Pamela Anderson 20 years ago?
    Andy
    @mindovermiles262
    ^^ @105ron that's the same as
    const currentUser = this.props.currentUser
    const email = this.props.email
    ?
    Rhys
    @105ron
    Hmm... before she had Hep C
    Yes
    Andy
    @mindovermiles262
    @105ron ++ thanks
    odin-bot
    @odin-bot
    Woot! @105ron now has 725 points
    Rhys
    @105ron
    Then if you change to a functional component you only need to change the destructuring line
    You can also use it in the function arguments too const Component = ( { currentUser, email } ) => {
    Javier M
    @Javier-Machin
    is Axios the most used fetch replacement?
    Cody Loyd
    @codyloyd
    i think so
    it's the one i hear about the most
    Javier M
    @Javier-Machin
    oh it does the .json() for you
    Cody Loyd
    @codyloyd
    right on
    hey i saw a relevant tweet today
    just a sec
    Arun Kumar Mohan
    @arku
    @Javier-Machin Not just that
    Javier M
    @Javier-Machin
    yeah I just found out about it
    reading right now
    Javier M
    @Javier-Machin
    oh, Wes is using await
    I was starting to think I was a weirdo for going for it over .then
    Arun Kumar Mohan
    @arku

    With fetch, you've to check if the response is ok

    It won't raise an exception if the server threw a 404

    Hold on
    Let me grab a link
    Javier M
    @Javier-Machin
    ahh I see
    so you have to throw the error if it doesn't come up with "ok"
    otherwise it won't trigger the catch
    weird
    Javier M
    @Javier-Machin
    Thanks for the info BTW @arun1595 ++ @codyloyd ++
    odin-bot
    @odin-bot
    Woot! @arun1595 now has 926 points