can’t access ‘this’ function in React callback

I have a React component where by I need to change the state after a successful database call. The database call uses a callback function, which I can’t change, however I can’t find a way to access the redirect function in the same component, from within the call back function. I just get the error enableRedirect' of null

I’ve tried changing the callback function to an arrow function, but then it doesn’t get called correctly. I’ve been reading other answers to similar problems, but can’t make it apply to my situation

    ...     componentDidUpdate = (prevProps, prevState) => {     if (prevState.braintreeToken !== this.state.braintreeToken) {        dropin.create(         {           authorization: this.state.braintreeToken,           container: "#dropin-container",         }, //callback function happens here         (createErr, instance) => {           button.addEventListener("click", function() {             instance.requestPaymentMethod(function(               requestPaymentMethodErr,               payload             ) {               api                 .submitPayload(payload, plan, id)                 .then(res => {                   //this is where I'm trying to call my enable redirect function                   this.enableRedirect();                 })                 .catch(err => {                   //error handling                 });             });           });         }       );     }   };      // the function I'm trying to call     enableRedirect = () => {       this.setState({         redirect: true       });     };  ... 

I need the enableRedirect Function to be called in the callback!

createBottomTabNavigator с окном, который в него не входит [[React Native]]

Нужно отобразить нижний бар (createBottomTabNavigator) с ссылками на другие страницы, но сам скрин не должен принадлежать этому бару.

Как такое можно сделать?

введите сюда описание изображения

Small styling discrepancies using React with Material-UI in SharePoint Online (non-SPFx)

When I build and publish my React application which uses Material-UI, to SharePoint Online I see a couple of small styling issues. It appears SPO’s styling is being inherited by my Material-UI components in some places and I’m wondering if there’s a way to better isolate them at the application level.

For example, my card action buttons function but are stretched horizontally. card action button

Also, my TextField components still have the nice floating label effect, but get a border around them. textfield elements

Note that this application is not a SPFx project. Thanks for any help!

How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?

So, it’s my understanding that in Japan it’s considered to be polite to say “itadakimasu” before eating. From what I’ve read, it seems that the meaning of this phrase derives from Buddhist and Shinto religious concepts, however, which gives rise to this question: how would the typical Japanese person respond to a foreigner (who might be a Christian, Muslim, or a member of some similar monotheistic faith) who refused to say it (as politely as possible) and cited religious reasons to do so?

Как обстоят дела с заказами по react?

подскажите пожалуйста начал осваивать технологию реакта . На данный момент уже 3 года занимаюсь созданием сайта на уровне верстке и интеграции, уже достиг потолка и четко чутка надоела. Начал изучать REact , пока интересно, благодаря базе и опыту по проектам, все учиться понятно. Но мне вот интересно есть ли заказы на Фрилансе( на RU и EN биржах) по react. Я видел много вакансии у компании, удаленно в офис и.тп. Но как дела идут с заказами с фриланса в 2019

Integrating Web Chat using React getting 403 Authorization error

Hi Below is the code I have adapted from https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/03.a.host-with-react

<!DOCTYPE html> <html lang="en-US">   <head>     <title>Web Chat: Integrate with React</title>     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <!--       For simplicity and code clarity, we are using Babel and React from unpkg.com.     -->     <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>     <script src="https://unpkg.com/react@16.5.0/umd/react.development.js"></script>     <script src="https://unpkg.com/react-dom@16.5.0/umd/react-dom.development.js"></script>     <!--       For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".       When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",       or lock down on a specific version with the following format: "/4.1.0/webchat.js".     -->     <script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>     <style>       html, body { height: 100% }       body { margin: 0 }        #webchat {         height: 100%;         width: 100%;       }     </style>   </head>   <body>     <div id="webchat" role="main"></div>     <script type="text/babel">         (async function () {         // In this demo, we are using Direct Line token from MockBot.         // To talk to your bot, you should use the token exchanged using your Direct Line secret.         // You should never put the Direct Line secret in the browser or client app.          const headers = {"Authorization", "Bearer <'secret key'>"}         const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', { method: 'POST' }, {Headers:headers} );          const { token } = await res.json();         const { ReactWebChat } = window.WebChat;          window.ReactDOM.render(         <ReactWebChat directLine={ window.WebChat.createDirectLine({ token }) } />,         document.getElementById('webchat')         );          document.querySelector('#webchat > *').focus();         })().catch(err => console.error(err));     </script>   </body> </html> 

Below is the Error I am getting enter image description here

Какие сайты хорошо подготовят к собеседованию React розроботчика?

Чтобы не создавать кучу тем, задам сразу 3 вопроса: 1. Какие сайты с тестами по React вы знаете? 2. Какие сайты с задачками по React вы знаете? 3. На собеседованиях по JS часто задают задачки, а по React вообще задают?Или только задают реализовать какую ту часть или интерфейс сайта? Сайты можно не только русские но и англоязычные

jest plus react – testing an onClick method

I am kinda new to jest and unit testing in general. I created a component that has a click handler. I would like to check that when I clicked it whether the state updated. However it always tells me “TypeError: Cannot read property ‘equal’ of undefined”. if I try to log the fidn result it doesn’t do anything. but i know there is a node inside of it because if i change the name it gives the error: “expect node to be 1 but found 0” Would anyone be kindly enough to give any pointers? cheers!

The component

import React from "react"; import PropTypes from "prop-types"; import { getFlag } from "../helpers/helperFucntions"; import CountrySportDetails from "./CountrySportDetails"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import {     faCaretDown,     faCaretUp,     faMedal } from "@fortawesome/free-solid-svg-icons";  class CountryListComponent extends React.Component {     state = {         detailsOpenStatus: false     };      toggleDetailsOpenStatus = () => {         this.setState({ detailsOpenStatus: !this.state.detailsOpenStatus });     };      render() {         const { countryDetails, sportslist } = this.props;         const flag = getFlag(countryDetails.c_Name);          let goldMedalCount = 0;         let silverMedalCount = 0;         let bronzeMedalCount = 0;          sportslist.map(sport => {             goldMedalCount += sport.GoldMedalList.length;             silverMedalCount += sport.SilverMedalList.length;             bronzeMedalCount += sport.BronzeMedalList.length;         });          const medals = (             <div className="country-listitem__medal-container">                 <div>                     <FontAwesomeIcon icon={faMedal} className="gold" /> {goldMedalCount}                 </div>                 <div>                     <FontAwesomeIcon icon={faMedal} className="silver" />{" "}                     {silverMedalCount}                 </div>                 <div>                     <FontAwesomeIcon icon={faMedal} className="bronze" />{" "}                     {bronzeMedalCount}                 </div>             </div>         );          console.log("medals", goldMedalCount, silverMedalCount, bronzeMedalCount);          const caret =             this.state.detailsOpenStatus === false ? (                 <FontAwesomeIcon icon={faCaretDown} />             ) : (                 <FontAwesomeIcon icon={faCaretUp} />             );          return (             <div                 className="country-listitem__countainer"                 onClick={this.toggleDetailsOpenStatus}             >                 <div className="country-listitem__flag-container">{flag}</div>                  <div className="country-listitem__country-name">                     {countryDetails.c_Name}                     {medals}                 </div>                  <div className="country-listitem__caret">{caret}</div>                  <CountrySportDetails                     sportslist={sportslist}                     openDetailsStatus={this.state.detailsOpenStatus}                 />             </div>         );     } }  CountryListComponent.propTypes = {     countryDetails: PropTypes.object.isRequired,     sportslist: PropTypes.array.isRequired };  export default CountryListComponent; 

The test

import React from "react"; import ReactDOM from "react-dom"; import CountryListComponent from "./CountryListComponent";  import { configure, shallow, mount } from "enzyme"; import Adapter from "enzyme-adapter-react-16"; import { isExpressionWrapper } from "@babel/types";  configure({ adapter: new Adapter() });  test("renders without crashing", () => {     shallow(<CountryListComponent countryDetails={{}} sportslist={[]} />); });  test("test the click handler", () => {     const container = mount(         <CountryListComponent countryDetails={{}} sportslist={[]} />     );     container.find(".country-listitem__countainer").simulate("click");     container.update();      expect(container.state("detailsOpenStatus")).to.equal(true); }); 

enter image description here