Skip to content

Tauri not detecting React state change #3909

Answered by dchicchon
dchicchon asked this question in Q&A
Discussion options

You must be logged in to vote

Just in case someone has this same issue, I was able to get my code working when I used useRef rather than useState hook.

Turns out my main issue was using the registerHotkeys function. Since I only called it once, it was not getting the updated state values. In order to fix this I also created an unregister function.

import React, { useState, useEffect, useRef } from 'react'
import { writeFile, readTextFile } from '@tauri-apps/api/fs';
import { open, save } from '@tauri-apps/api/dialog';
import hotkeys from 'hotkeys-js';
import './App.css'

const OPEN_FILE_HOTKEY = 'ctrl+o, command+o';
const SAVE_FILE_HOTKEY = 'ctrl+s, command+s';

function App() {
  const textRef = useRef()
  useEffect(() 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dchicchon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant