Your problem is you need to read up on asynchronous programming in JavaScript, such as https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing
The grpc_web call is setting up a callback, and the reason the code jumps around is that the code isn't being run yet. It will be executed at a later time when the RPC finishes. You can reproduce the same issue without grpc using the following code: ```javascript function getBook() { var bookTitle; setTimeout(0, () => { bookTitle = "Hello World"; console.log(bookTitle); }); console.log(bookTitle); return bookTitle; } ``` Here, the callback set in the timeout function will be called after getBook returns. You need to modify your code to make it asynchronous. The same problem would arise with any other asynchronous javascript library. On Sat, Feb 6, 2021 at 8:12 AM Jeff Steger <be26...@gmail.com> wrote: > I dont know react. But this problem almost certainly has nothing to do > with grpc. It probably has to do with either the nature of variable scoping > in react or (more probably) the lifetime of the message object (and > assignment sematics in react). You need React expertise, not grpc > expertise. > > On Sat, Feb 6, 2021 at 8:56 AM Yasaswini Gadde < > yasaswinigadde...@gmail.com> wrote: > >> >> Hi sir, we are used grpc-web package in react native for developing >> mobile application. When I am calling a >> GetBook() function . it is running linearly up to line number 17 then >> suddenly it is jumping line number 31 and after executing remaining lines >> control is moving to line 18 and calling grpc unary function. In line 26 >> bookTitle variable is showing a value but In line number 27 when we are >> trying to return it , it is showing undefined. Please help us >> >> -- >> You received this message because you are subscribed to the Google Groups >> "grpc.io" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to grpc-io+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/grpc-io/CAGibBBwCBNgx-j4oOM%3Dqd-u1ZOYxM89fbvff3bZ2BtuJL5xNBw%40mail.gmail.com >> <https://groups.google.com/d/msgid/grpc-io/CAGibBBwCBNgx-j4oOM%3Dqd-u1ZOYxM89fbvff3bZ2BtuJL5xNBw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups " > grpc.io" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to grpc-io+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/grpc-io/CAA-WHukQYLUh7t8kzh-XkpW7yxOMx%2B5CDzs5q95zvwhn20JiFg%40mail.gmail.com > <https://groups.google.com/d/msgid/grpc-io/CAA-WHukQYLUh7t8kzh-XkpW7yxOMx%2B5CDzs5q95zvwhn20JiFg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAEvr0PHABC8F%3DLuUU1ik6fVGutjxzV4SLTCiTJSMd_-ApA1NhQ%40mail.gmail.com.