Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                

<div id="root">
  
</div>
              
            
!

CSS

              
                #addRecipe 
  
   background-color: #4CAF50 /* Green */
   
   color: white
   padding: 15px 32px
   text-align: center
   text-decoration: none
   display: inline-block
   font-size: 16px  
#ingredients
   visibility: hidden

    
  
  
   
  
 
              
            
!

JS

              
                
class RecipeBox extends React.Component {
constructor(props) {
    super(props);
    this.state = {food: '', ingredients: '', count: 0, foodArray: JSON.parse(localStorage.getItem('text')) || [], ingredArray: JSON.parse(localStorage.getItem('text2')) || [], buttonBool: false, div: document.createElement('div'), localStorageArray: [],localStorageArray2: []};

  
  
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  
  var locArray=[]
  var areaArray=[]
  var areaArray2=[]
  
  var text1 = JSON.parse(localStorage.getItem('text'));
  
   var text2 = JSON.parse(localStorage.getItem('text2'));
  
 
  
  for (var x in text1){
    this.state.localStorageArray.push(text1[x])
 
  
    
  }
  
  for (var z in text2){
    this.state.localStorageArray2.push(text2[z])  
    
  }
  
  var counting=[];
  
  for (let y=0;y<this.state.localStorageArray.length;y++){
    

  
     counting.push(0)
   
    
    var countingy=document.getElementById('counting'+y);
    
  var btn = document.createElement("BUTTON");        // Create a <button> element
var t = document.createTextNode(this.state.localStorageArray[y]); 
    
    
    
    
    btn.id='btn'+y;
  
    // Create a text node
btn.appendChild(t);     
    
    // Append the text to <button>
document.body.appendChild(btn); 
    
  locArray.push(this.state.localStorageArray2[y])
  document.getElementById('btn'+y).onclick = function(){
    
        


 
    counting[y]++;
    localStorage.setItem('count'+y, ((counting[y])))
     if ((localStorage.getItem('count'+y))==1){
      var area = document.createElement("textarea");
    
    function change(){
        
         areaArray.splice(y,0,area.value);
        localStorage.setItem('area'+y, (JSON.stringify(areaArray[y])))
       
       }
         
      
      area.id='area'+y;
                            
        document.body.appendChild(area); 
                       
   
     area.addEventListener('change', change, false);         

  
       
       if (JSON.parse(localStorage.getItem('area'+y)!=undefined)){
             
      document.getElementById('area'+y).value=((localStorage.getItem('area'+y)))
       
            }
       else{
        
   document.getElementById('area'+y).value=(locArray[y]);
     
       }
       
     
       
       
     }
  else if ((localStorage.getItem('count'+y))>1){

              
    if (document.getElementById('area'+y).style.visibility!='hidden')
           (document.getElementById('area'+y)).style.visibility='hidden'
        
        
       else
          (document.getElementById('area'+y).style.visibility='visible')
    }
      
  }

  }
  
}
  componentDidMount() {
    console.log((this.state.localStorageArray));
    
  }
  
  handleChange(event) {
    this.setState({ [event.target.name]: event.target.value });
    

  }

 
  
  handleSubmit(event) {
    
   this.setState({ counter: this.state.counter + 1});
   var counter=0;
    
    
    alert('A name was submitted: ' + event.target.food.value+ event.target.ingredients.value);
    this.state.foodArray.push(event.target.food.value)
    
    
   this.state.ingredArray.push(event.target.ingredients.value)
   
    
 
    localStorage.setItem('text', (JSON.stringify(this.state.foodArray)))
    
    localStorage.setItem('text2', (JSON.stringify(this.state.ingredArray)))
      
    

 
  this.state.div.appendChild(event.target.food.value)
    
    
  }

    
     

  render() {
   
    return (
         
                                      
      <div>
      <form onSubmit={this.handleSubmit}>
        <label>
          Food:
            </label>
          <input type="text" name="food"  onChange={this.handleChange} />
         
       
        
        
        <label>Ingredients</label>
        <input type="text" name="ingredients"  onChange={this.handleChange} />
        <input type="submit" value="Submit" />
      </form>
   
        <div>
          <p>
            
   { ((localStorage.getItem('text')) != '')
    ?
      (((this.state.localStorageArray)))
              
             
   
  :  "test"
   
   }
            
             {this.state.foodArray.map(food => (<button>{food}</button>))}
          </p>
        </div>
       </div>
    );
  }

}
ReactDOM.render(
  <RecipeBox />,
  document.getElementById('root')
);


              
            
!
999px

Console