Check out example codes for "retrieve fields from multiple objects into visualforce". It will help you in understanding the concepts better.

Code Example 1

public class myController{

     public ObjectA__c myA      {get;set;}
     public ObjectB__c myB      {get;set;}

     public myController(){
          myA = new ObjectA__c();
          myB = new ObjectB__c();
     }

     public void saveObjects(){
          insert myA;
          myB.ObjectA__c = myA.Id;
          insert myB;
     }

}

Learn ReactJs, React Native from akashmittal.com