How to use the react-redux.useSelector function in react-redux

To help you get started, we’ve selected a few react-redux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streetmix / streetmix / assets / scripts / info_bubble / DebugHoverPolygon.jsx View on Github external
const DebugHoverPolygon = (props) => {
  // When the window / viewport resizes, set the width and
  // height of the canvas element.
  const el = useRef(null)

  const enabled = useSelector(
    (state) => state.flags.INFO_BUBBLE_HOVER_POLYGON.value || false
  )
  const hoverPolygon = useSelector(
    (state) => state.infoBubble.hoverPolygon || []
  )

  const handleResize = () => {
    if (!el.current) return

    el.current.width = window.innerWidth
    el.current.height = window.innerHeight
  }

  useEffect(() => {
    window.addEventListener('resize', handleResize)
    return () => {
      window.removeEventListener('resize', handleResize)
    }
  })
github BadIdeaFactory / the-emoji-compass / src / components / CompassNeedleResponse.js View on Github external
function CompassNeedleResponse (props) {
  const symbols = useSelector(state => state.app.symbols)
  const activeNeedle = useSelector(state => state.app.activeNeedle)
  const dispatch = useDispatch()
  const el = useRef(null)

  const initialRotation = random() * 360 // Set at random start position

  // for now auto-rotate 1 number on render.
  const numberOfSymbols = symbols.length
  const randomNumbers = getUniqueRandomIntegers(numberOfSymbols, 3)
  const responseEmojis = randomNumbers.map((num) => symbols[num])
  const rotateDirection = Math.round(random()) ? 1 : -1
  const rotateQuantity = Math.ceil(random()) // a number between 2 and 3 inclusive
  const rotateTo = getRotation(randomNumbers[0], numberOfSymbols)

  // calc rotate to: if diff between current and destination is less than
  // one full rotation, then add a full rotation.
github jhackshaw / ofnotes / src / containers / App.jsx View on Github external
const App = () => {
  const classes = useStyles();
  const dispatch = useDispatch();
  const menuExpanded = useSelector(selectMenuOpen)

  const toggleMenuOpen = e => {
    dispatch(actions.setMenuOpen(!menuExpanded))
  }


  return (
    
      

      <div>
        
        </div>
github iran-react-community / elegant-react-native / app / view / pages / todos / index.js View on Github external
const Todos = () =&gt; {
  const {appStyle, todosStyle} = style;

  const dispatch = useDispatch();
  const {goBack} = useNavigation();
  const [todoText, setTodoText] = useState('');

  const todos = useSelector(selectTodos);

  const _addTodo = () =&gt; {
    if (todoText !== '') {
      dispatch(addTodo(todoText));
      setTodoText('');
    }
  };

  const _goBack = () =&gt; goBack();
  const _toggleTodo = id =&gt; dispatch(toggleTodo(id));
  const _deleteTodo = id =&gt; dispatch(deleteTodo(id));

  return (
github AdguardTeam / AdGuardHome / client / src / components / Logs / Cells / ClientCell.js View on Github external
const ClientCell = ({
    client,
    client_id,
    client_info,
    domain,
    reason,
}) => {
    const { t } = useTranslation();
    const dispatch = useDispatch();
    const autoClients = useSelector((state) => state.dashboard.autoClients, shallowEqual);
    const processingRules = useSelector((state) => state.filtering.processingRules);
    const isDetailed = useSelector((state) => state.queryLogs.isDetailed);
    const [isOptionsOpened, setOptionsOpened] = useState(false);

    const autoClient = autoClients.find((autoClient) => autoClient.name === client);
    const source = autoClient?.source;
    const whoisAvailable = client_info && Object.keys(client_info.whois).length > 0;
    const clientName = client_info?.name || client_id;
    const clientInfo = client_info && {
        ...client_info,
        whois_info: client_info?.whois,
        name: clientName,
    };

    const id = nanoid();
github Altinn / altinn-studio / src / Altinn.Apps / AppFrontend / react / altinn-app-frontend / src / features / confirm / containers / Confirm.tsx View on Github external
const Confirm = (props: IConfirmProps) =&gt; {
  const classes = useStyles();

  const [appName, setAppName] = React.useState('');
  const [attachments, setAttachments] = React.useState([]);
  const [lastChangedDateTime, setLastChangedDateTime] = React.useState('');
  const [instanceMetaObject, setInstanceMetaObject] = React.useState({});
  const [userLanguage, setUserLanguage] = React.useState('nb');
  const [isSubmitting, setIsSubmitting] = React.useState(false);

  const applicationMetadata: IApplicationMetadata = useSelector((state: IRuntimeState) =&gt; state.applicationMetadata.applicationMetadata);
  const instance: IInstance = useSelector((state: IRuntimeState) =&gt; state.instanceData.instance);
  const language: any = useSelector((state: IRuntimeState) =&gt; state.language.language);
  const parties: IParty[] = useSelector((state: IRuntimeState) =&gt; state.party.parties);
  const validations: IValidations = useSelector((state: IRuntimeState) =&gt; state.formValidations.validations);

  const routeParams: any = props.match.params;

  const { instanceId } = window as Window as IAltinnWindow;
  const layout = useSelector((state: IRuntimeState) =&gt; state.formLayout.layout);
  const textResources = useSelector((state: IRuntimeState) =&gt; state.textResources.resources);

  const isLoading = (): boolean =&gt; (
    !attachments ||
    !instanceMetaObject ||
    !lastChangedDateTime ||
    !appName ||
    !instance ||
    !lastChangedDateTime ||
    !parties
github GenesisVision / web-client / packages / social-trader / src / pages / programs / programs-settings / program-settings.page.tsx View on Github external
const _ProgramsEditPage: React.FC = () =&gt; {
  const dispatch = useDispatch();

  const createProgramInfo = useSelector(createProgramInfoSelector);
  const description = useSelector(programDescriptionSelector);
  const isProgram = description &amp;&amp; description.programDetails;

  const updateDescription = useCallback(
    () =&gt; dispatch(dispatchProgramDescriptionWithId(description!.id)),
    [description]
  );

  return (
     (
github sebastienbarbier / seven23_webapp / src / app / components / nomadlist / CityDetails.js View on Github external
useEffect(() => {
    if (statistics) {
      const c = statistics.cities.find(c => c.place_slug == slug);
      setCity(c);
      setTitle(c.place);
    }
  }, [slug, statistics]);

  const selectedCurrency = useSelector(state =>
    state.account
      ? state.currencies.find(c => c.id === state.account.currency)
      : null
  );

  const nomadlist = useSelector(state =>
    state.user.socialNetworks ? state.user.socialNetworks.nomadlist || {} : {}
  );

  const [isModified, setIsModified] = useState(false);

  const reduxTransaction = useSelector(state => state.transactions);

  const [isSaving, setIsSaving] = useState(false);

  const saveModification = () => {
    setIsSaving(true);
    dispatch(
      AccountsActions.setPreferences({
        nomadlist: categoriesToExclude
      })
    )
github alexakasanjeev / magento_react_native / src / containers / categoryList / CategoryListContainer / index.js View on Github external
const CategoryListContainer = ({ categoryId }) =&gt; {
  const dispatch = useDispatch();
  const items = useSelector(state =&gt; state.categoryList.items);
  const currencySymbol = useSelector(state =&gt; state.magento.currency.default_display_currency_symbol);
  const totalCount = useSelector(state =&gt; state.categoryList.totalCount);
  const status = useSelector(state =&gt; state.categoryList.status);
  const errorMessage = useSelector(state =&gt; state.categoryList.errorMessage);
  const loadingMoreStatus = useSelector(state =&gt; state.categoryList.loadingMoreStatus);
  const dispatchOpenSelectedProductAction = (product, children) =&gt; dispatch(openSelectedProduct(product, children));
  const loadProducts = (_categoryId, offset, sortOrder) =&gt; dispatch(getCategoryProducts(_categoryId, offset, sortOrder));
  const showHorizontalList = false;
  const columnCount = 2;
  const canLoadMoreProducts = items.length &lt; totalCount;

  const stateAccessor = 'categoryList';

  return (