title: Post from React to Ruby (not rails)
body: <p>I have created a Twitter clone using Ruby in the backend and React in the front end. I have managed to fetch all tweets and I am trying to post a tweet. It is connected but it is posting nothing. Literally an empty tweet.</p>
  <p>Below is the React code.</p>
  <pre class="lang-js prettyprint-override"><code>const TweetsFeed = () =&gt; {
    const [tweet, setTweet] = useState(&quot;&quot;);
  
    const tweetChangeHandler = (event) =&gt; {
      event.preventDefault();
      setTweet(event.target.value);
    };
  
  const postTweet = async () =&gt; {
      const postRequest = {
        method: &quot;POST&quot;,
        params: tweet,
      };
      fetch(&quot;http://127.0.0.1:9292/tweets&quot;, postRequest).then((response) =&gt;
        response.json().then((data) =&gt; {
          console.log(data);
        })
      );
      fetchTweets();
    };
  </code></pre>
  <p>Below is the Ruby route and create method code</p>
  <pre class="lang-rb prettyprint-override"><code>post '/tweets' do
    Tweet.create(tweet: params[:tweet])
  end
  
  def self.create(tweet:)
    result = DatabaseConnection.query(&quot;INSERT INTO tweets (tweet) VALUES ('#{tweet}') RETURNING id, tweet;&quot;)
    Tweet.new(
      id: result[0][0], 
      tweet: result[0][1]
    )
  end
  </code></pre>
  <p>Below is the form</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form className=&quot;new-tweet-form&quot; action=&quot;/tweets&quot; method=&quot;post&quot;&gt;
    &lt;div className=&quot;pp-input&quot;&gt;
      &lt;img src=&quot;./images/pp1.jpg&quot; alt=&quot;&quot; /&gt;
      &lt;input
        type=&quot;text&quot;
        name=&quot;tweet&quot;
        placeholder=&quot;What's happening?&quot;
        onChange={tweetChangeHandler}
      /&gt;
    &lt;/div&gt;
    &lt;div className=&quot;extras-button&quot;&gt;
      &lt;Extras /&gt;
      &lt;Button type=&quot;button&quot; onClick={postTweet}&gt;
        Tweet
      &lt;/Button&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  <p>It does post to the database, but an empty tweet everytime.</p>